2392

/*
多重背包

发现一个小规律,所有的相同类型的物品必须放在一起,这样可以对物品类型拍个序,按照不能超过的高度排序
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a) (a<<1)
#define Y(a) (a>>1)

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int DP[40011];
struct node
{
	int h;
	int a;
	int c;
	friend bool operator<(node a,node b)
	{
		return a.a<b.a;
	}
};
node data[410];
int N;
int main()
{
	read;
	write;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
	{
		scanf("%d %d %d",&data[i].h,&data[i].a,&data[i].c);
	}
	sort(data+1,data+N+1);
	memset(DP,0,sizeof(DP));
	for(int i=1,j;i<=N;i++)
	{
		//对该物品进行二进制分解
		j = 1;
		while(j<data[i].c)
		{
			//进行一次01背包
			for(int k=data[i].a;k>=0;k--)
			{
				if(k-j*data[i].h<0) break;
				DP[k] = TMAX(DP[k],DP[k-j*data[i].h]+j*data[i].h);
			}

			data[i].c-=j;
			j*=2;
		}
		j = data[i].c;
		for(int k=data[i].a;k>=0;k--)
		{
			if(k-j*data[i].h<0) break;
			DP[k] = TMAX(DP[k-j*data[i].h]+j*data[i].h,DP[k]);
		}
	}

	for(int k=data[N].a;k>=0;k--)
	{
		if(DP[k]==k)
		{
			printf("%d\n",k);
			break;
		}
	}
	return 0;
}

posted @ 2011-04-15 14:39  AC2012  阅读(280)  评论(0编辑  收藏  举报