标签:
Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 #define maxn 1000+10 8 int val[maxn], weight[maxn], p[maxn]; 9 int main() 10 { 11 int T; 12 cin >> T; 13 while (T--) 14 { 15 int n, vol; 16 cin >> n >> vol; 17 for (int i = 1; i <= n; i++) 18 { 19 cin >> p[i]; 20 } 21 for (int j = 1; j <= n; j++) 22 { 23 cin >> weight[j]; 24 } 25 for (int j = 0; j <= vol; j++) 26 { 27 val[j] = 0; 28 } 29 for (int i = 1; i <= n; i++) 30 { 31 for (int j = vol; j >= weight[i]; j--) 32 { 33 val[j] = max(val[j], val[j - weight[i]] + p[i]); 34 35 } 36 } 37 cout << val[vol] << endl; 38 39 } 40 return 0; 41 42 }
心得:
背包入门~~~~理解一个方程还是挺费劲的,/(ㄒoㄒ)/~~不过终于比之前好多了。。。。给自己一个赞!不过还是觉得好神奇
(*^__^*) 嘻嘻……
标签:
原文地址:http://www.cnblogs.com/Lynn0814/p/4721406.html