题意:

有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. hdu2015

    http://acm.hdu.edu.cn/showproblem.php?pid=2015 #include<iostream> #include<stdio.h> #inc ...

  2. lintcode :Count and Say 报数

    题目: 报数 报数指的是,按照其中的整数的顺序进行报数,然后得到下一个数.如下所示: 1, 11, 21, 1211, 111221, ... 1 读作 "one 1" -> ...

  3. lintcode :Remove Duplicates from Sorted Array 删除排序数组中的重复数字

    题目: 删除排序数组中的重复数字 给定一个排序数组,在原数组中删除重复出现的数字,使得每个元素只出现一次,并且返回新的数组的长度. 不要使用额外的数组空间,必须在原地没有额外空间的条件下完成.  样例 ...

  4. *[codility]AscendingPaths

    https://codility.com/programmers/challenges/magnesium2014 图形上的DP,先按照路径长度排序,然后依次遍历,状态是使用到当前路径为止的情况:每个 ...

  5. 转:samba 启动和重新启动 以及在虚拟系统和实际系统怎么实现软件交换

    转自:http://blog.csdn.net/zwhfyy/article/details/1605151 启动 smb start 重新启动 root 用户登陆 CHQ_WEB:/etc/init ...

  6. C++:虚基类

    4.4.3 虚基类1.没什么要引入虚基类 如果一个类有多个直接基类,而这些直接基类又有一个共同的基类,则在最底层的派生类中会保留这个间接的共同基类数据成员的多分同名成员.在访问这些同名的成员时,必须在 ...

  7. 3、JPA一些常用的注解

    常用注解有下面这些: ①:@Entity.@Table.@Id.@GeneratedValue.@Column.@Basic ②:@Transient 用于忽略某个属性,而不对该属性进行持久化操作 ③ ...

  8. android休眠唤醒流程2

    android系统一段时间没有操作,    屏幕(screen)将从高亮(bright)变为暗淡(dim),如果再过段时间还是没有操作,屏幕(screen)从暗淡(dim)变为关闭(off).这时,系 ...

  9. Maven远程仓库

    根据Apache Maven声明:"只有当在本地和中心仓库找不到所需的依赖文件,才会到远程仓库去下载". 当在Maven里声明了一个本地和中心仓库都没有的库文件时,Maven会停止 ...

  10. Ubuntu 安装mod_python配置Apache2

    在Ubuntu上搭建Python运行环境,mod_python是不可少的(据说mod_swgi也是可以的,没有亲测).使用命令安装mod_python. 安装: apt-get install lib ...