poj2241 = hdu1069

来源:互联网 发布:黑客帝国数字雨 算法 编辑:程序博客网 时间:2024/05/21 10:14
<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
原创粉丝点击