题意:

有n个,长x宽y高z的长方体,把这些长方体摞起来,上面长方体底面的长宽一定要小于下面的,求能摞的最大高度。

分析:

一个长方体,可以有三种放法,先把所有放的状态存起来,按底面升序排列,dp[i]前i个能构成的最大高度,dp[i]=max(dp[i],dp[j]+h)  h为当前长方体高度

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <queue>
  6. #include <stack>
  7. #include <cstdio>
  8. #include <vector>
  9. #include <string>
  10. #include <cctype>
  11. #include <complex>
  12. #include <cassert>
  13. #include <utility>
  14. #include <cstring>
  15. #include <cstdlib>
  16. #include <iostream>
  17. #include <algorithm>
  18. using namespace std;
  19. typedef pair<int,int> PII;
  20. typedef long long ll;
  21. #define lson l,m,rt<<1
  22. #define rson m+1,r,rt<<11
  23. #define All 1,N,1
  24. #define read freopen("in.txt", "r", stdin)
  25. const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
  26. const int INF= 0x7ffffff;
  27. const int maxn = 1e5+;
  28. const int mod = ;
  29. struct Block{
  30. int x;
  31. int y;
  32. int z;
  33. }b[];
  34. bool cmp(Block u,Block v){
  35. if(u.x==v.x)return u.y>v.y;
  36. else return u.x>v.x;
  37. }
  38. int dp[],n;
  39. int solve(int num){
  40. memset(dp,,sizeof(dp));
  41. sort(b,b+num,cmp);
  42. int ma=-;
  43. for(int i=;i<num;++i){
  44. dp[i]=b[i].z;
  45. for(int j=;j<i;++j){
  46. if(b[j].y>b[i].y&&b[j].x>b[i].x)
  47. dp[i]=max(dp[i],dp[j]+b[i].z);
  48. }
  49. if(dp[i]>ma)
  50. ma=dp[i];
  51. }
  52. return ma;
  53. }
  54. int main()
  55. {int t=,xx,yy,zz;
  56. while(~scanf("%d",&n)){
  57. if(n==)break;
  58. t++;
  59. int num=;
  60. for(int i=;i<n;++i){
  61. scanf("%d%d%d",&xx,&yy,&zz);
  62. b[num].x=xx;b[num].y=yy;b[num].z=zz;
  63. num++;
  64. b[num].x=yy;b[num].y=xx;b[num].z=zz;
  65. num++;
  66. b[num].x=zz;b[num].y=yy;b[num].z=xx;
  67. num++;
  68. b[num].x=yy;b[num].y=zz;b[num].z=xx;
  69. num++;
  70. b[num].x=xx;b[num].y=zz;b[num].z=yy;
  71. num++;
  72. b[num].x=zz;b[num].y=xx;b[num].z=yy;
  73. num++;
  74. }
  75. /* for(int i=0;i<num;++i)
  76. printf("%d %d %d\n",b[i].x,b[i].y,b[i].z);*/
  77. printf("Case %d: maximum height = %d\n",t,solve(num));
  78. }
  79. return ;
  80. }

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

    The Tower of Babylon Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Subm ...

  4. POJ2241——The Tower of Babylon

    The Tower of Babylon Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2207   Accepted: 1 ...

  5. UVA437-The Tower of Babylon(动态规划基础)

    Problem UVA437-The Tower of Babylon Accept: 3648  Submit: 12532Time Limit: 3000 mSec Problem Descrip ...

  6. DAG 动态规划 巴比伦塔 B - The Tower of Babylon

    题目:The Tower of Babylon 这是一个DAG 模型,有两种常规解法 1.记忆化搜索, 写函数,去查找上一个符合的值,不断递归 2.递推法 方法一:记忆化搜索 #include < ...

  7. HOJ 1438 The Tower of Babylon(线性DP)

    The Tower of Babylon My Tags Cancel - Seperate tags with commas. Source : University of Ulm Internal ...

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

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

  9. [动态规划]UVA437 - The Tower of Babylon

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

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

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

随机推荐

  1. SNAT

    http://blog.chinaunix.net/uid-2628744-id-2454879.html

  2. POJ 2407 Relatives(欧拉函数)

    题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...

  3. jQuery从主页面存取控制 iframe 中的元素,参数及方法

    从主页面上获取iframe下的某个对象,或使用iframe下的方法,或是获取iframe下某个doc元素,要求兼容各类浏览器,不仅仅ie; $(function() { $('#abgne_ifram ...

  4. jquery cookie 用法

    jquery cookie 用法 $.cookie("name","value","options")  当不设置options时,此coo ...

  5. Bessie的体重问题

    P1028 Bessie的体重问题 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 USACO OCT09 8TH  描述 Bessie像她的诸多姊妹一样,因 ...

  6. 李洪强漫谈iOS开发[C语言-038]-if else if语句

    李洪强漫谈iOS开发[C语言-038]-if else if语句

  7. Spring3 报org.aopalliance.intercept.MethodInterceptor问题解决方法

    原文:Spring3 报org.aopalliance.intercept.MethodInterceptor问题解决方法 一 开发环境:JDK5+Spring3.0.5+Myeclipse6.6+T ...

  8. 使用 Spring 3 来创建 RESTful Web Services(转)

    使用 Spring 3 来创建 RESTful Web Services 在 Java™ 中,您可以使用以下几种方法来创建 RESTful Web Service:使用 JSR 311(311)及其参 ...

  9. UDP丢包和无序 问题的解决方法

    最近在做一个项目,在这之前,做了个验证程序. 发现客户端连续发来1000个1024字节的包,服务器端出现了丢包现象. 纠其原因,是服务端在还未完全处理掉数据,客户端已经数据发送完毕且关闭了. 我用过s ...

  10. java web 下实现文件下载

    来自:http://blog.csdn.net/longshengguoji/article/details/39433307 需求:实现一个具有文件下载功能的网页,主要下载压缩包和图片 两种实现方法 ...