标签:bag value vol port htm different cout content i++
1 5 10 1 2 3 4 5 5 4 3 2 1Sample Output
14
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int dp[1005],n,v,nv[1005],nm[1005],t; 6 while(cin>>t) 7 { 8 while(t--) 9 { 10 memset(dp,0,sizeof(dp)); /*初始化*/ 11 scanf("%d %d",&n,&v); /*读取骨头数量和背包重量*/ 12 for(int i = 0; i < n; i++) /*每一个骨头的价值*/ 13 scanf("%d",&nv[i]); 14 for(int i = 0; i < n; i++) /*每个骨头的重量*/ 15 scanf("%d",&nm[i]); 16 17 for(int i = 0; i < n; i++) 18 for(int j = v; j >= nm[i];j--) /*dp算法*/ 19 dp[j] = max(dp[j],dp[j-nm[i]]+nv[i]); 20 cout<<dp[v]<<endl; 21 } 22 } 23 24 return 0; 25 }
参考博客:
标签:bag value vol port htm different cout content i++
原文地址:http://www.cnblogs.com/jj81/p/7287397.html