HDU 4508

祼的完全背包问题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL __int64
using namespace std;

LL dp[100005];
struct Food{
	int a,b;
}fd[105];


int main(){
	int n,m;
	while(scanf("%d",&n)!=EOF){
		for(int i=1;i<=n;i++)
		scanf("%d%d",&fd[i].a,&fd[i].b);
		scanf("%d",&m);
		memset(dp,0,sizeof(dp));
		LL ans=0;
		for(int k=1;k<=n;k++){
			for(int i=0;i<=m-fd[k].b;i++){
				dp[i+fd[k].b]=max(dp[i+fd[k].b],dp[i]+fd[k].a);
				ans=max(dp[i+fd[k].b],ans);
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

  

posted @ 2015-03-26 10:09  chenjunjie1994  阅读(108)  评论(0编辑  收藏  举报