您的位置:首页 > 其它

UVA 437 十九 The Tower of Babylon

2015-08-30 20:48 465 查看
The Tower of Babylon
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVA 437

Appoint description:
System Crawler (2015-08-29)

Description

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

struct Node
{
int l;
int r;
int h;
int s;
};

Node a[100];

bool cmp(Node p,Node q)
{
return p.s<q.s;
}

int main()
{
int N,n;
int i,j,k=1;
int dp[100];
while(scanf("%d",&N)!=EOF && N!=0)
{
n=0;
memset(dp,0,sizeof(dp));
for(i=1;i<=N;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
n++;
a
.l=max(x,y),a
.r=min(x,y),a
.h=z,a
.s=x*y;
n++;
a
.l=max(x,z),a
.r=min(x,z),a
.h=y,a
.s=x*z;
n++;
a
.l=max(z,y),a
.r=min(z,y),a
.h=x,a
.s=z*y;
}

sort(a+1,a+n+1,cmp);
dp
=a
.h;
int ans=dp
;
for(i=n-1;i>=1;i--)
{
int max=0;
for(j=i+1;j<=n;j++)
{
if(a[i].l<a[j].l && a[i].r<a[j].r && dp[j]>max)
max=dp[j];
}
dp[i]=max+a[i].h;
if(dp[i]>ans)
ans=dp[i];
}

printf("Case %d: maximum height = %d\n",k++,ans);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: