提交时间:2024-04-07 20:53:32
运行 ID: 142402
#include<iostream> #include<algorithm> using namespace std; int w[10010],c[10010],dp[10010][10010]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int m,t; cin>>t>>m; for(int i = 1; i <= m; i++){ cin>>w[i]>>c[i]; } for(int i = 1; i <= m; i++){ for(int j = 1;j <= t; j++){ if(j >= w[i]){ dp[i][j] = max(dp[i-1][j-w[i]]+c[i],dp[i-1][j]); }else{ dp[i][j] = dp[i-1][j]; } } } cout<<dp[m][t]; return 0; }