Bone Collector
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 48618 Accepted Submission (s): 20269
Problem Description
Many years ago, in Teddy ' s hometown there is a man whowas called "Bone Collector". Collect varies of bones, such asdog ' 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 Collectingthere is a lot of bones, obviously , different bone have different value anddifferent volume, now given the each bone ' s value along his trip, can Youcalculat E out the maximum of the total value the bone collector can get?
Input
The first line contain a integer T, the number of cases.
Followed by T cases, each case three lines, the first line contain Twointeger N, V, (N <=, v <=) repre Senting the number of Bonesand the volume of his bag. And the second line contain N integers representingthe value of each bone. The third line contain N integers representing thevolume of each bone.
Output
One integer per line representing the maximum of Thetotal value (this number would be is less than 231).
Sample Input
1
5 10
1 2 3) 4 5
5 4 3) 2 1
Sample Output
14
Note: Enter the value of each bone first and then enter the volume of each bone.
State transition equation: Dp[j]=max (dp[j],dp[j-v[i]]+w[i].
#include <iostream>#include<string.h>using namespacestd;intn,v;intdp[1111];intw[1111],v[1111];intMain () {intT; while(cin>>t) { while(t--) {cin>>N>>V; for(intI=1; i<=n;i++) {cin>>W[i]; } for(intI=1; i<=n;i++) {cin>>V[i]; } memset (DP,0,sizeof(DP)); for(intI=1; i<=n;i++){ for(intj=v;j>=v[i];j--) {//J if less than v[i] then v[i] must not be loaded into the bagDp[j]=max (dp[j],dp[j-v[i]]+W[i]); }} cout<<dp[V]<<Endl; } } return 0;}
Hdu2602bone Collector Simple 0-1 backpack