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. 手机端js模拟长按事件(代码仿照jQuery)

    代码编写: $.fn.longPress = function(fn) { var timeout = undefined; var $this = this; for(var i = 0;i< ...

  2. [OrangePi] Backup internal EMMC to SD Card

    Boot your Orange PI board from EMMC without SD Card inserted login insert your SD Card Run: sudo ins ...

  3. linux中使用软链接时出现 too many levels of symbolic links

    刚开始使用的源文件的路径是相对路径,所以导致标题中的这种错误. 只要用绝对路径表示源文件就好了.如果用相对路径的话,实际相对的是目标文件所在的路径,而在创建链接文件时用的路径是相对于当前的路径.

  4. jquery冲突细节

    使用jquery报一个错误,之前也遇到过,今天记录下来,方便以后使用 Uncaught TypeError: Object #<Object> has no method 'test' 这 ...

  5. yii2中表单的字段标签名称

    1.以登陆页面为例,默认是英文的,在loginForm.php中添加attributeLabels,可以变成中文 具体代码如下: public function attributeLabels(){  ...

  6. Ul li 竖排 菜单

    Ul li 竖排 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  7. 161110、彻底征服 Spring AOP 之 实战篇

    Spring AOP 实战 看了上面这么多的理论知识, 不知道大家有没有觉得枯燥哈. 不过不要急, 俗话说理论是实践的基础, 对 Spring AOP 有了基本的理论认识后, 我们来看一下下面几个具体 ...

  8. iOS 学习笔记 十三 (2015.04.15)采用第三方库,实现ios录音转为amr

    1.第三方开源库地址 https://github.com/guange2015/ios-amr 2.参考博客地址 http://blog.csdn.net/windsoul85/article/de ...

  9. java几道简单的面试题目

    1.   请问以下程序会输出什么? public   class   Test   {  public   static   void   main(String[]   args)   {  Par ...

  10. laravel页面间的传值

    可以在前端页面元素上添加onclick事件  onclick='selectRaw(this)' js中写function selectRaw(obj){ var data=$(obj).attr(& ...