The simple 01 backpack is very clear.
I have a suggestion to answer all questions about a backpack.
Bone Collector
Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 27979 accepted submission (s): 11404
Problem descriptionpolicyears ago, in Teddy's hometown there was a man who was called "Bone Collector ". this man like to 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 his trip of collecting there are a lot of bones, obviusly, different bone has different value and different volume, now given the each bone's value along his trip, Can you calculate out the maximum of the total value the bone collector can get?
Inputthe first line contain a integer t, the number of instances.
Followed by T cases, each case three lines, the first line contain two integer N, V, (n <= 1000, v <= 1000) representing 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 of each bone.
Outputone integer per line representing the maximum of the total value (This number will be 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
/* Problem Analysis: Enter the value of the bone in the second row [1001], in the second line, input volume of the bone [1001]. We want to obtain the state equation DP [I] [J] = max (DP [I-1] [J], DP [I-1] [J-volume [I] + value [I]) equation explanation: when loading the I bone, we should consider the value of the DP [I] [J] for loading the I bone, we need to compare the value of loading I with that without installing I. If I is not loaded, the I-1 is loaded into the package with a volume of J. When I is loaded, the I-1 is loaded into the package with a volume of J-volume [I ]., however, because I is loaded, value [I] is added. */# include <iostream> # include <cstring> using namespace STD; int max (int, int B) {If (A> B) return a; else return B;} int main (int I, Int J) {int t; // test example int N; // total number of bones int V; // total package volume int static DP [1001] [1001]; // The final maximum value int value [1001]; // value of a single bone int volume [1001]; // volume of a single bone CIN> T; while (t --) {CIN> N> V; for (I = 1; I <= N; I ++) CIN> value [I]; for (I = 1; I <= N; I ++) cin> volume [I]; memset (DP, 0, sizeof (DP); for (I = 1; I <= N; I ++) {for (j = 0; j <= V; j ++) {If (j> = Volume [I]) DP [I] [J] = max (DP [I-1] [J], DP [I-1] [J-volume [I] + value [I]); else DP [I] [J] = DP [I-1] [J] ;}} cout <DP [N] [v] <Endl ;}return 0 ;}