http://acm.hdu.edu.cn/showproblem.php?pid=2602
Bone Collector
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 32408 Accepted Submission (s): 13329
Problem Descriptionmany years ago, in Teddy ' s hometown there is a man who was called "Bone Collector". Collect varies of bones, such as dog ' s, cow ' s, also he went to the grave ... The bone collector had a big bag with a volume of V, and along he trip of collecting there is a lot of bones, obviously , different bone have different value and different volume, now given the each bone's value along his trips, can you CALCU Late out the maximum of the total value the bone collector can get? Inputthe first line contain a integer T, the number of cases. Followed by T cases, each case three lines, the first line contain both integer n, V, (N <=, v <=) repr Esenting the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume for each bone. Outputone integer per line representing the maximum of the total value (this number would be is less than 231). Sample INPUT1 5 1 2 3 4 5 5 4 3 2 1 Sample Output14 analysis: http://blog.csdn.net/dapengbusi/article/details/7463968
1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intv[ +],w[1005];6 intn,c;7 intf[1005][1005];//for DP (I,J), the optional item is the maximum value of the items placed in the backpack when the I...N backpack capacity is J (total weight). 8 voidbackpack ()9 {Ten inti,j; One for(i=1; i<=n;i++) A for(j=0; j<=c;j++) - { - if(i==1) thef[i][j]=0; - Else -f[i][j]=f[i-1][j]; - if(j>=V[i]) +F[i][j]=max (f[i][j],f[i-1][j-v[i]]+w[i]); - } +printf"%d\n", F[n][c]); A } at intMain () - { - intT; -scanf"%d",&t); - while(t--) - { in inti; -scanf"%d%d",&n,&c); to for(i=1; i<=n;i++) +scanf"%d",&w[i]); - for(i=1; i<=n;i++) thescanf"%d",&v[i]); * backpack (); $ }Panax Notoginseng return 0; -}
HDU 2602 Bone Collector