HDU 2602 Bone Collector

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602

 

简单01背包

 

#include <iostream>
#define MAX( a, b ) ((a>b)?(a):(b)) 
using namespace std;
typedef struct 
{
	int value;
	int weight;
}bone;
__int64 dp[1005];
bone data[1005];
int main()
{
	int t;
	int i,j;
	int n,v;			
	cin>>t;
	while(t--)
	{
		cin>>n>>v;
		for (i=0;i<=v;i++)
			dp[i]=0;
		for(i=0;i<n;i++)
			cin>>data[i].value;
		for (i=0;i<n;i++)
			cin>>data[i].weight;

		for (i=0;i<n;i++)
			for(j=v;j>=data[i].weight;j--)
				dp[j]=MAX(dp[j],dp[j-data[i].weight]+data[i].value);
		cout<<dp[v]<<endl;
	}
	return 0;
}


 

你可能感兴趣的:(Collector)