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. 1
  2. 10 20 30
  3. 2
  4. 6 8 10
  5. 5 5 5
  6. 7
  7. 1 1 1
  8. 2 2 2
  9. 3 3 3
  10. 4 4 4
  11. 5 5 5
  12. 6 6 6
  13. 7 7 7
  14. 5
  15. 31 41 59
  16. 26 53 58
  17. 97 93 23
  18. 84 62 64
  19. 33 83 27
  20. 0

Sample Output

  1. Case 1: maximum height = 40
  2. Case 2: maximum height = 21
  3. Case 3: maximum height = 28
  4. Case 4: maximum height = 342
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. struct Node
  7. {
  8. int l;
  9. int r;
  10. int h;
  11. int s;
  12. };
  13.  
  14. Node a[];
  15.  
  16. bool cmp(Node p,Node q)
  17. {
  18. return p.s<q.s;
  19. }
  20.  
  21. int main()
  22. {
  23. int N,n;
  24. int i,j,k=;
  25. int dp[];
  26. while(scanf("%d",&N)!=EOF && N!=)
  27. {
  28. n=;
  29. memset(dp,,sizeof(dp));
  30. for(i=;i<=N;i++)
  31. {
  32. int x,y,z;
  33. scanf("%d %d %d",&x,&y,&z);
  34. n++;
  35. a[n].l=max(x,y),a[n].r=min(x,y),a[n].h=z,a[n].s=x*y;
  36. n++;
  37. a[n].l=max(x,z),a[n].r=min(x,z),a[n].h=y,a[n].s=x*z;
  38. n++;
  39. a[n].l=max(z,y),a[n].r=min(z,y),a[n].h=x,a[n].s=z*y;
  40. }
  41.  
  42. sort(a+,a+n+,cmp);
  43. dp[n]=a[n].h;
  44. int ans=dp[n];
  45. for(i=n-;i>=;i--)
  46. {
  47. int max=;
  48. for(j=i+;j<=n;j++)
  49. {
  50. if(a[i].l<a[j].l && a[i].r<a[j].r && dp[j]>max)
  51. max=dp[j];
  52. }
  53. dp[i]=max+a[i].h;
  54. if(dp[i]>ans)
  55. ans=dp[i];
  56. }
  57.  
  58. printf("Case %d: maximum height = %d\n",k++,ans);
  59. }
  60. return ;
  61. }

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. 让git忽略文件模式的改变

    使用git的过程中发现,就算文件的内容没改变,只有文件的权限改变的话,git也会检测到文件被修改了. 解决方法是配置一下: git config --global core.filemode fals ...

  2. Oracle体系结构总览(整理)

    先让我们来看一张图  这张就是Oracle 9i的架构全图.看上去,很繁杂.是的,是这样的.现在让我们来梳理一下:一.数据库.表空间.数据文件1.数据库数据库是数据集合.Oracle是一种数据库管理系 ...

  3. 爱普生 RS330 打印机墨水连供装置墨盒吸墨复位方法

    芯片复位方法: 先按充墨键(墨水灯按键),一下一下按,把墨车按停到右侧换墨盒的位置为止(就是右侧框框正中位置), 全程带电操作,停到换墨盒的位置后再按住芯片复位键(墨盒芯片上面白色的小按键)5秒以上再 ...

  4. Delphi 的各版本定义,用于预编译参数中,避免忘记备忘之

    DELPHI的版本宏: VER80 - Delphi 1 VER90 - Delphi 2 VER100 - Delphi 3 VER120 - Delphi 4 VER130 - Delphi 5 ...

  5. linux设备驱动归纳总结(十一):写个简单的看门狗驱动【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-112879.html linux设备驱动归纳总结(十一):写个简单的看门狗驱动 xxxxxxxxxxx ...

  6. 161014、Comet4J介绍及使用(即时推送)

    简介 Comet4J是一个微型的即时推送框架(类似于goeasy),它分为服务端与客户端两部分,你只要将服务器端(JAR文件,目前仅支持Tomcat6.7)放入WEB-INF\lib,客户端(Java ...

  7. mysql-5.5.28源码安装过程中错误总结

    介绍一下关于mysql-5.5.28源码安装过程中几大错误总结,希望此文章对各位同学有所帮助.系统centOS 6.3 mini (没有任何编译环境)预编译环境首先装了众所周知的 cmake(yum ...

  8. HDU 2136:Computer(树形DP)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 Computer     Description A school bought the fi ...

  9. [lua]lua简介

    在这篇文章中,我想向大家介绍如何进行Lua程序设计.我假设大家都学过至少一门编程语言,比如Basic或C,特别是C.因为Lua的最大用途是在宿主程序中作为脚本使用的. Lua 的语法比较简单,学习起来 ...

  10. {A} + {B} 分类: HDU 2015-07-11 18:06 6人阅读 评论(0) 收藏

    {A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...