The Tower of Babylon

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

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

Description

 

Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:

The babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions  . A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They wanted to construct the tallest tower possible by stacking blocks. The problem was that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.

Your job is to write a program that determines the height of the tallest tower the babylonians can build with a given set of blocks.

Input and Output

The input file will contain one or more test cases. The first line of each test case contains an integer n, representing the number of different blocks in the following data set. The maximum value for n is 30. Each of the next n lines contains three integers representing the values  ,  and  .

Input is terminated by a value of zero (0) for n.

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Casecase: maximum height =height"

Sample Input

1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0

Sample Output

Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; struct Node
{
int l;
int r;
int h;
int s;
}; Node a[]; bool cmp(Node p,Node q)
{
return p.s<q.s;
} int main()
{
int N,n;
int i,j,k=;
int dp[];
while(scanf("%d",&N)!=EOF && N!=)
{
n=;
memset(dp,,sizeof(dp));
for(i=;i<=N;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
n++;
a[n].l=max(x,y),a[n].r=min(x,y),a[n].h=z,a[n].s=x*y;
n++;
a[n].l=max(x,z),a[n].r=min(x,z),a[n].h=y,a[n].s=x*z;
n++;
a[n].l=max(z,y),a[n].r=min(z,y),a[n].h=x,a[n].s=z*y;
} sort(a+,a+n+,cmp);
dp[n]=a[n].h;
int ans=dp[n];
for(i=n-;i>=;i--)
{
int max=;
for(j=i+;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 ;
}

UVA 437 十九 The Tower of Babylon的更多相关文章

  1. UVa 437 The Tower of Babylon(经典动态规划)

    传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details ...

  2. UVa 437 The Tower of Babylon

    Description   Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...

  3. UVa 437 The Tower of Babylon(DP 最长条件子序列)

     题意  给你n种长方体  每种都有无穷个  当一个长方体的长和宽都小于还有一个时  这个长方体能够放在还有一个上面  要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法  比較不好控制 ...

  4. uva The Tower of Babylon[LIS][dp]

    转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...

  5. UVA The Tower of Babylon

    The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many det ...

  6. 「kuangbin带你飞」专题十九 矩阵

    layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...

  7. 无废话ExtJs 入门教程十九[API的使用]

    无废话ExtJs 入门教程十九[API的使用] extjs技术交流,欢迎加群(201926085) 首先解释什么是 API 来自百度百科的官方解释:API(Application Programmin ...

  8. Python之路【第十九章】:Django进阶

    Django路由规则 1.基于正则的URL 在templates目录下创建index.html.detail.html文件 <!DOCTYPE html> <html lang=&q ...

  9. Bootstrap <基础二十九>面板(Panels)

    Bootstrap 面板(Panels).面板组件用于把 DOM 组件插入到一个盒子中.创建一个基本的面板,只需要向 <div> 元素添加 class .panel 和 class .pa ...

随机推荐

  1. beta阶段组间的140字互评

    第一名:连连看 理由:此项目组的技术难度最大,而且在游戏背景和界面上有很大的改进,观赏性和趣味性很足. 第二名:新蜂 理由:俄罗斯方块游戏能运行,新增加了暂停和分数显示的功能,就是界面不是很美观. 第 ...

  2. Silverlight ModelView中调用UI进程

    Silverlihgt:  Deployment.Current.Dispatcher.BeginInvoke wpf: App.Current.Dispatcher.Invoke  

  3. Android学习参考

    收到一些朋友的微博私信,说能不能给Android新手们一些指导,我只能说指导谈不上,毕竟我也很多东西正在学习中,与此同时一大学同学准备转行Android,可以说是从头开始,那么我就姑且以一个过来人的身 ...

  4. 160926、Java-SpringMVC统一异常处理

    从零开始学 Java - Spring MVC 统一异常处理 看到 Exception 这个单词都心慌 如果有一天你发现好久没有看到Exception这个单词了,那你会不会想念她?我是不会的.她如女孩 ...

  5. android 中通过代码创建控件

    package bvb.de.openadbwireless.circle; import android.annotation.TargetApi; import android.app.Activ ...

  6. Android使用Application总结

    对于application的使用,一般是 在Android源码中对他的描述是; * Base class for those who need to maintain global applicati ...

  7. Temporary Tables and the TableType Property [AX 2012]

    Temporary Tables and the TableType Property [AX 2012] 1 out of 1 rated this helpful - Rate this topi ...

  8. 12、Jsp加强/自定义标签/JavaBean

    1 Jsp加强回顾 Jsp加强 1)Jsp的9大内置对象 request       HttpServletRequet response     HttpServletResponse config ...

  9. awk 手册--【转载】

    1. 前言 有关本手册 : 这是一本awk学习指引,  其重点着重于 : l         awk 适于解决哪些问题 ? l         awk 常见的解题模式为何 ? 为使读者快速掌握awk解 ...

  10. java 练习题

    题目:想控制台输1-3个整数,按顺序为年,月,日.#号键结束输入.若输入一个整数,则为年份,程序判断是闰年还是平年:若输入两个整数,则为年份和月份,程序将输出该年的月份的天数:若输入3个整数:则为年, ...