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 Input
15 101 2 3 4 55 4 3 2 1
Sample Output
14
Authorteddysourcehdu 1st "Vegetable-birds Cup" programming Open Contest idea: 01 backpack nude
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 using namespacestd;7 8 Long Longva[1005];9 intvo[1005];Ten Long Longdp[1005]; One A intMain () - { - intt,n,v,i,j; thescanf"%d",&T); - while(t--) - { -scanf"%d%d",&n,&v); + for(i=1; i<=n;i++) -scanf"%lld",&va[i]); + for(i=1; i<=n;i++) Ascanf"%d",&vo[i]); atMemset (DP,0,sizeof(DP)); - for(i=1; i<=n;i++) - { - for(j=v;j>=vo[i];j--) - { -Dp[j]=max (dp[j],dp[j-vo[i]]+va[i]); in } - } toprintf"%lld\n", Dp[v]); + } - return 0; the}
"01 Backpack" HDU 2602 Bone Collector (template title)