hdu2602 Bone Collector (01背包)

#include <stdio.h>
#include <string.h>
#define MAXN 1002
//01背包
struct node
{
	int vol,val;
}bone[MAXN];

int main()
{
	int N,V,test,i,j;
	int dp[MAXN];
	scanf("%d",&test);
	while(test--)
	{
		memset(dp,0,sizeof(dp));
		scanf("%d %d",&N,&V);
		for(i=0;i<N;++i)
			scanf("%d",&bone[i].val);
		for(i=0;i<N;++i)
			scanf("%d",&bone[i].vol);
		for (i=0;i<N;++i)
		{
			for(j=V;j>=bone[i].vol;--j)
				if(dp[j]<dp[j-bone[i].vol]+bone[i].val)
					dp[j]=dp[j-bone[i].vol]+bone[i].val;
		}
		printf("%d\n",dp[V]);
	}
	return 0;
}

你可能感兴趣的:(hdu2602 Bone Collector (01背包))