1 solutions
-
1
#include <bits/stdc++.h> using namespace std; int n,m,dp[31][201]; vector<pair<int,int> > thing; int main(){ scanf("%d%d",&m,&n); thing.push_back(make_pair(0,0)); for(int i = 1;i<=n;i++){ int a,b; scanf("%d%d",&a,&b); thing.push_back(make_pair(a,b)); } for(int i = 1;i<=n;i++) for(int j = 1;j<=m;j++) if(j<thing[i].first)dp[i][j] = dp[i-1][j]; else dp[i][j] = max(dp[i-1][j],dp[i][j-thing[i].first]+thing[i].second); printf("max=%d",dp[n][m]); return 0; }
Information
- ID
- 534
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 9
- Tags
- # Submissions
- 11
- Accepted
- 4
- Uploaded By