poj2241 = hdu1069

14 篇文章 0 订阅
7 篇文章 0 订阅
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(40, 85, 126);">题:http://poj.org/problem?id=2241
</span>
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; background-color: rgb(40, 85, 126);">意:已知有n(n<30)种类型的block,以及它们的长宽高,每种类型的block都有无限多个。问如果把他们叠起来(上面block的底面的长宽,必须比下面的block的底面长宽都短),最高能有多高。</span>
#include<iostream>	//poj2241 DAG上的DP
#include<cstdio>	
#include<list>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>
using namespace std;
int dp[100000 + 5];
 
struct Node 
{
    int l,w,h;
    void newday(int x,int y,int z)
	{
        l = x,w = y, h = z; 
    }
}node[100000 + 5];
bool cmp(Node x,Node y) 
{
    return x.l * x.w < y.l * y.w;
}
int main() 
{
    int n,i,j,k;
    int Case = 0;
	//cout<<EXIT_SUCCESS<<endl;
    while(scanf("%d",&n),n) 
	{
		memset(dp,0,sizeof(dp));
		memset(node,0,sizeof(node));
        int tot = 0;
        for( i=1;i<=n;i++) 
		{
            int x,y,z;
            scanf("%d %d %d",&x,&y,&z);
            node[++tot].newday(x,y,z);
            node[++tot].newday(x,z,y);
            node[++tot].newday(y,x,z);
            node[++tot].newday(y,z,x);
            node[++tot].newday(z,x,y);
            node[++tot].newday(z,y,x);
        }
        sort(node + 1,node + tot,cmp);
        for(i=1;i<=tot;i++)  dp[i] = node[i].h;
        int ans = 0;
        for( i=2;i<=tot;i++) 
		{
            for( j=1;j<i;j++) //类似拦截导弹
			{ 
				if(node[i].l> node[j].l && node[i].w > node[j].w)
                    dp[i] = _cpp_max(dp[i],dp[j] + node[i].h);
            }
            if( ans < dp[i])ans = dp[i];
        }
        printf("Case %d: maximum height = %d\n",++Case,ans);
		//cout<<EXIT_SUCCESS<<endl;
    }
    return EXIT_SUCCESS;	//EXIT_FAILURE		#define EXIT_SUCCESS 200
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值