标签:
70 3
71 100
69 1
1 2
3
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; const int maxn = 1005; int f[maxn],w[maxn],v[maxn],n,m; int main(){ cin>>m>>n; for(int i = 1;i <= n;i++){ cin>>w[i]>>v[i]; } for(int i = 1;i <= n;i++){ for(int j = m;j >= w[i];j--){ f[j] = max(f[j],f[j-w[i]] + v[i]); } } cout<<f[m]; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5754622.html