UVA437 The Tower of Babylon

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA437 The Tower of Babylon相关的知识,希望对你有一定的参考价值。

题解:

DAG最长路裸题

注意DAG最长路,先是建图,然后记忆化搜索即可

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define ll long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))  
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 
#define INF 1e9
typedef pair<int,int> P;
const double eps=1e-9;
const int maxnnode=11000;
const int maxn=100100;
const int mod=20071027;

struct Node{
    int w,s,h;
}node[300];

int Edge[300][300];
int dp[300],tmp;

int DP(int i){
    int& cnt=dp[i];
    if(cnt) return cnt;
    cnt=node[i].h;
    for(int j=1;j<=tmp;j++){
        if(Edge[i][j]) cnt=max(cnt,node[i].h+DP(j));
    }
    return cnt;
}

int main()
{
    int Kase=1;
    int n;
    while(~scanf("%d",&n)&&n){
        int W,H,S;
        tmp=1;
        CLR(Edge);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&W,&H,&S);
            node[tmp].w=W;node[tmp].h=H;node[tmp++].s=S;
            node[tmp].w=H;node[tmp].h=W;node[tmp++].s=S;
            node[tmp].w=S;node[tmp].h=H;node[tmp++].s=W;
            node[tmp].w=W;node[tmp].h=S;node[tmp++].s=H;
            node[tmp].w=H;node[tmp].h=S;node[tmp++].s=W;
            node[tmp].w=S;node[tmp].h=W;node[tmp++].s=H;
        }
        tmp--;
        for(int i=1;i<=tmp;i++)
        for(int j=1;j<=tmp;j++){
            if(node[i].w>node[j].w&&node[i].s>node[j].s) Edge[i][j]=1;
            if(node[i].w<node[j].w&&node[i].s<node[j].s) Edge[j][i]=1;
        }
        int ans=0;
        for(int i=1;i<=tmp;i++){
            CLR(dp);
            ans=max(ans,DP(i));
        }
        printf("Case %d: maximum height = %d\n",Kase++,ans);
    }
    return 0;
}

 

以上是关于UVA437 The Tower of Babylon的主要内容,如果未能解决你的问题,请参考以下文章

Uva437 The Tower of Babylon

uva 437 The Tower of Babylon

The Tower of Babylon UVA - 437

UVA437 The Tower of Babylon

UVA 437 The Tower of Babylon

uva437-The Tower of Babylon