题目要求:
Problem Description
Many years 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 , obviously , 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 ?

The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , 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 ?

Input
The first line contain a integer T , the number of cases.
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.
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.
Output
One integer per line representing the maximum of the total value (this number will be less than 231).
解题思路:
简单的0-1背包问题,这里不再赘述。
代码如下:
# include <iostream>
# include <algorithm>
using namespace std;
struct node
{
int value;
int volume;
}bone[1002];
int value[1002];
int main()
{
freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
int n,v;
scanf("%d%d",&n,&v);
int i,j;
for(i=0;i<n;i++)
scanf("%d",&bone[i].value);
for(i=0;i<n;i++)
scanf("%d",&bone[i].volume);
memset(value,0,sizeof(value));
for(i=0;i<n;i++)
{
for(j=v;j>=bone[i].volume;j--)
{
value[j]=max(value[j],value[j-bone[i].volume]+bone[i].value);
}
}
printf("%d\n",value[v]);
}
return 0;
}