题意:

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

分析:

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

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int maxn = 1e5+;
const int mod = ;
struct Block{
int x;
int y;
int z;
}b[];
bool cmp(Block u,Block v){
if(u.x==v.x)return u.y>v.y;
else return u.x>v.x;
}
int dp[],n;
int solve(int num){
memset(dp,,sizeof(dp));
sort(b,b+num,cmp);
int ma=-;
for(int i=;i<num;++i){
dp[i]=b[i].z;
for(int j=;j<i;++j){
if(b[j].y>b[i].y&&b[j].x>b[i].x)
dp[i]=max(dp[i],dp[j]+b[i].z);
}
if(dp[i]>ma)
ma=dp[i];
}
return ma;
}
int main()
{int t=,xx,yy,zz;
while(~scanf("%d",&n)){
if(n==)break;
t++;
int num=;
for(int i=;i<n;++i){
scanf("%d%d%d",&xx,&yy,&zz);
b[num].x=xx;b[num].y=yy;b[num].z=zz;
num++;
b[num].x=yy;b[num].y=xx;b[num].z=zz;
num++;
b[num].x=zz;b[num].y=yy;b[num].z=xx;
num++;
b[num].x=yy;b[num].y=zz;b[num].z=xx;
num++;
b[num].x=xx;b[num].y=zz;b[num].z=yy;
num++;
b[num].x=zz;b[num].y=xx;b[num].z=yy;
num++;
}
/* for(int i=0;i<num;++i)
printf("%d %d %d\n",b[i].x,b[i].y,b[i].z);*/
printf("Case %d: maximum height = %d\n",t,solve(num));
}
return ;
}

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. TDD三个阶段

    TDD的三个阶段 红灯.绿灯.重构 :明确了实施TDD所要遵循的工作流 (需求--->测试-->代码[重构]) 红灯阶段:      为不存在的代码编写测试 绿灯阶段:      仅编写适 ...

  2. 深入浅出Java并发包—锁(Lock)VS同步(synchronized)

    今天我们来探讨一下Java中的锁机制.前面我们提到,在JDK1.5之前只能通过synchronized关键字来实现同步,这个前面我们已经提到是属于独占锁,性能并不高,因此JDK1.5之后开始借助JNI ...

  3. java打印时间精确到毫秒

    package net.floodlightcontroller.conflict; import java.io.*; import java.util.*; import java.text.Si ...

  4. 对于linux下system()函数的深度理解(整理)

    原谅: http://blog.sina.com.cn/s/blog_8043547601017qk0.html 这几天调程序(嵌入式linux),发现程序有时就莫名其妙的死掉,每次都定位在程序中不同 ...

  5. svn:...target\classes\META-INF\MANIFEST.MF (系统找不到指定的路径。)

    在上传项目到svn时,pom.xml报错

  6. 一个不错的log4j.properties例子

    # Set root logger level to WARN and append to stdout #在开发环境下日志级别要设置成DEBUG,生产环境设置成info或error log4j.ro ...

  7. 31. Next Permutation

    题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...

  8. java对象实例化

    JAVA类,只要知道了类名(全名)就可以创建其实例对象,通用的方法是直接使用该类提供的构造方法,如 NewObject o = new NewObject(); NewObject o = new N ...

  9. TCP和UDP协议的应用/参数查看

    TCP发送的包有序号,对方收到包后要给一个反馈,如果超过一定时间还没收到反馈就自动执行超时重发,因此TCP最大的优点是可靠.一般网页(http).邮件(SMTP).远程连接(Telnet).文件(FT ...

  10. 成为一个PHP专家:缺失的环节

    这一篇文章是“Becoming a PHP Professional”系列 4 篇博文中的第 1 篇. 当浏览各类与PHP相关的博客时,比如Quora上的问题,谷歌群组,简讯和杂志,我经常注意到技能的 ...