POJ2392

题目显然是一个比较复杂的多重背包。因为现在每个方块还有独自的高度限制。那么我们就把方块按他们的最大限制高度排序后再做分解即可,注意分解的时候分解后的每个方块高度要在原来方块基础上乘上块数。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct block{
    int h,c,a;
}G[405];
bool cmp(block a,block b)
{
    return a.a<b.a;
}
struct block G1[4005];
int cnt=0;
void get(int n)
{
    for(int i=0;G[n].c>=(1<<i);i++){
        G1[++cnt].a=G[n].a;G1[cnt].h=G[n].h*(1<<i);G1[cnt].c=1<<i;G[n].c-=(1<<i);
    }
    if(G[n].c){
        G1[++cnt].a=G[n].a;G1[cnt].h=G[n].h*G[n].c;G1[cnt].c=G[n].c;
    }
}
bool f[40005];
int main()
{
    int k,i,j;
    cin>>k;
    for(i=1;i<=k;i++)scanf("%d%d%d",&G[i].h,&G[i].a,&G[i].c);
    sort(G+1,G+1+k,cmp);
    for(i=1;i<=k;i++)get(i);
    f[0]=true;int maxn=0;
    for(i=1;i<=cnt;i++)
        for(int V=G1[i].a;V>=G1[i].h;V--)
            if(f[V-G1[i].h]) {
                f[V] = true;
                maxn = max(maxn, V);
            }
     cout<<maxn<<endl;

    return 0;

}

猜你喜欢

转载自blog.csdn.net/humveea6/article/details/79899679
POJ