problem Description
Many years ago, in Teddy ' s hometown there were a man he 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 bone s, obviously, different bone have different value and different volume, now given the all bone ' s value along his trip, Can calculate 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 both integer n, V, (N <=, 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 for each bone.
Output
One integer per line representing the maximum of the total 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**
Test instructions: Backpack with a capacity of V, as much as possible to load more stone, output backpack the greatest value
Train of thought: the classic routine of the 01 backpack, pushed by the stone 1 to the stone N, under the I-stone backpack capacity v maximum value by i-1 recursion
#include <stdio.h> #include <string.h> #define N + int num[n+10],w[n+10],v[n+
10];
int main () {int i, J;
int T, n, V;
scanf ("%d", &t);
while (T--) {memset (num,0,sizeof (num));
Memset (W,0,sizeof (w));
memset (v,0,sizeof (v));
scanf ("%d%d", &n,&v);
for (i = 1; I <= n; i + +) scanf ("%d", &w[i]);
for (i = 1; I <= n; i + +) scanf ("%d", &v[i]); for (i = 1; I <= n; i + +) for (j = V; J >=v[i];j-)/*j represents the remaining capacity of the backpack */{NUM[J]
= Max (num[j],num[j-v[i]]+w[i]);
/*NUM[J] means that the value of the first stone is not put into the backpack *//*num[j-v[i]]+w[i] means the value of the first stone into the backpack */* Compare the best solution of the two to deposit num[j]*/
} printf ("%d\n", Num[v]);
} return 0; }