Input
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
Sample Input
1 5 10 1 2 3 4 5 5 4 3 2 1
Sample Output
14
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int f[10005];
int v[10005],w[10005];
int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
int i,j;
int t,n,V;
scanf("%d",&t);
while(t--)
{
memset(f,0,sizeof(f));
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>=0;j--)
{
if(j>=v[i])
{
f[j]=max(f[j],f[j-v[i]]+w[i]);
}
}
}
printf("%d\n",f[V]);
}
return 0;
}