Bone Collector
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 39828 Accepted Submission (s): 16514
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 Input15 101 2 3 4 55 4 3 2 1
Sample Output14
Authorteddy
Sourcehdu 1st "Vegetable-birds Cup" programming Open Contest
#include <cstdio>#include<iostream>#include<sstream>#include<cmath>#include<cstring>#include<cstdlib>#include<string>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<algorithm>using namespacestd;#definell Long Long#define_cle (M, a) memset (M, A, sizeof (m))#defineRepu (I, A, b) for (int i = A; I < b; i++)#defineREPD (I, A, b) for (int i = b; i >= A; i--)#defineSFI (n) scanf ("%d", &n)#defineSFL (n) scanf ("%i64d", &n)#definePFI (n) printf ("%d\n", N)#definePFL (n) printf ("%i64d\n", N)#defineMAXN 1005intDP[MAXN];intV[MAXN];intP[MAXN];intMain () {intT; SFI (T); while(t--) {_cle (DP,0); intN, M; SFI (n), SFI (m); Repu (i,0, N) SFI (P[i]); Repu (i,0, N) SFI (V[i]); Repu (i,0, N) for(intj = m; J >= V[i]; j--) Dp[j]= Max (Dp[j], Dp[j-v[i]] +P[i]); PFI (Dp[m]); } return 0;}
View Code
HDU 2602 (01 backpack)