Bone CollectorTime
limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 39612 Accepted Submission (s): 16412
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
Authorteddy
Sourcehdu 1st "Vegetable-birds Cup" programming Open Contest
Recommendlcy | We have carefully selected several similar problems for you:1203 2159 2955 1171 2191
Statistic | Submit | Discuss | Note
Very regular 0 1 knapsack problem.
The first row is value, the second row is the volume
#include <stdio.h> #include <string.h>int main () {int n,v;int ncase,dp[1005],val[1005],vol[1005];scanf ("% D ", &ncase), while (ncase--) {memset (dp,0,sizeof (DP)); memset (Val,0,sizeof (Val)); Memset (Vol,0,sizeof (vol)); scanf ("%d%d", &n,&v), for (int i=0;i<n;i++) scanf ("%d", &val[i]), and for (int i=0;i<n;i++) scanf ("%d", &vol[i]); int max=0;for (int i=0;i<n;i++) {for (int j=v;j>=vol[i];j--) {if (Dp[j]<dp[j-vol[i]]+val[i]) dp[j ]=dp[j-vol[i]]+val[i];if (Dp[j]>max) max=dp[j];} printf ("%d\n", Max);}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
hdu2602 Bone Collector (knapsack problem)