提交时间:2023-01-12 16:21:27

运行 ID: 67324

#include<bits/stdc++.h> using namespace std; int timer[10001],value[10001],dp[101][10001]={0}; int m,n,k=0; int main(){ //freopen("medic.in","r",stdin); //freopen("medic.out","w",stdout); cin>>m>>n; for(int i=1;i<=n;i++){ cin>>timer[i]>>value[i]; k+=timer[i]; } if(k<T) T=k; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(timer[i]<=j) dp[i][j]=max(dp[i-1][j],dp[i-1][j-timer[i]]+value[i]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][m]<<endl; }