标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 3477 Accepted Submission(s):
1753
1 #include <iostream> /*w完全背包*/ 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 int max(int x,int y) 6 { 7 return x>y?x:y; 8 } 9 int f[100001]; 10 int main() 11 { 12 int n,i,j,v,k; 13 int w[101],val[101]; 14 while(cin>>n) 15 { 16 memset(f,0,sizeof(f)); 17 for(i=1;i<=n;i++) 18 cin>>val[i]>>w[i]; 19 cin>>v; 20 for(i=1;i<=n;i++) 21 { 22 for(j=w[i];j<=v;j++) 23 { 24 f[j]=max(f[j],f[j-w[i]]+val[i]); 25 } 26 } 27 cout<<f[v]<<endl; 28 } 29 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4693733.html