提交时间:2023-01-08 15:56:44
运行 ID: 3492
#include<bits/stdc++.h> using namespace std; int c[55],v[55]; int dp[55][605]; int main(){ int n,m; cin>>m>>n; for(int i=1;i<=n;i++)cin>>c[i]>>v[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(j>=c[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-c[i]]+v[i]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][m]; return 0; } /* #include<cstdio> freopen("文件名.in","r",stdin); freopen("文件名.out","w",stdout); */