HDU 1069 (累积木)

大意:有n种积木,每种有无限多个,问面积大在下,小在上,最高能有多高。

思路:给定无限种其实最多每种有三个积木可以用,然后进行面积的排序(面积或边长排序),进行DP(注意dp时条件为下边两边长一定大于上面两边长,一次不能按照面积排)。

#include<map>
#include<queue>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
#include<algorithm>
#define LL __int64
#define inf 0x3f3f3f3f
const double PI=acos(-1.0);
using namespace std;
LL dp[1000010];
struct node{
    LL x,y,c,v;
}q[1000010];
struct no{
    LL s,x,y,c;
    bool operator<(const no p)const{
        return s>p.s;
    }
}Q[1000010];

int main(){
    LL n,m,i,j,k,cla=1,t;
    while(~scanf("%I64d",&n)&&n){
        for(i=0;i<n;i++){
            scanf("%I64d %I64d %I64d",&q[i].x,&q[i].y,&q[i].c);
        }
        int t=0;

        for(i=0;i<n;++i){
            Q[t].x=q[i].x,Q[t].y=q[i].y,Q[t].c=q[i].c;
            Q[t++].s=q[i].x*q[i].y;

            Q[t].x=q[i].x,Q[t].y=q[i].c,Q[t].c=q[i].y;
            Q[t++].s=q[i].x*q[i].c;

            Q[t].x=q[i].c,Q[t].y=q[i].y,Q[t].c=q[i].x;
            Q[t++].s=q[i].c*q[i].y;
        }

        sort(Q,Q+t);
        memset(dp,0,sizeof(dp));
        LL ans=0;
        for(i=0;i<t;++i){
            dp[i]=Q[i].c;
            for(j=0;j<i;++j){
                if( ((Q[i].x<Q[j].x&&Q[i].y<Q[j].y)||(Q[i].x<Q[j].y&&Q[i].y<Q[j].x))&&dp[i]<dp[j]+Q[i].c  ){
                    dp[i]=dp[j]+Q[i].c;
                }
            }
            if(ans<dp[i])
                ans=dp[i];
        }
        printf("Case %I64d: maximum height = %I64d\n",cla++,ans);
    }
    return 0;
}

你可能感兴趣的:(dp)