题意:

有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. HDU 3501 Calculation 2 (欧拉函数)

    题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...

  2. 匿名用户访问sharepoint2010中的列表

    Allow anonymous users to access listitems on a publishing site in SharePoint 2010 https://knowledge. ...

  3. [hackerrank]The Love-Letter Mystery

    https://www.hackerrank.com/contests/w3/challenges/the-love-letter-mystery 简单题. #include <cstdlib& ...

  4. IOS中实现图片点击全屏预览

    //// ViewController.m// XWZoomImageView//// Created by xiao on 15/11/13.// Copyright © 2015年 xiao. A ...

  5. Qt学习记录--Qt::CaseSensitive

    Qt::CaseSensitivity 为枚举类型, 可取值Qt::CaseSensitive 和 Qt::CaseInsensitive, 表示匹配的灵敏度. 比较字符串的时候 Qt::CaseSe ...

  6. iOS 用命令实现简单的打包过程

    `xcode-select --print-path`/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication // 获得打包 ...

  7. LA 6047 Perfect Matching 字符串哈希

    一开始我用的Trie+计数,但是不是计多了就是计少了,后来暴力暴过去的…… 看了别人的代码知道是字符串哈希,但是仍有几个地方不理解: 1.26^500溢出问题 2.没考虑哈希碰撞? 跪求指点! #in ...

  8. sql 随笔 2015-06-30

    清除多余字符 --清除多余字符 --' --char(9) 水平制表符 --char(10)换行键 --char(13)回车键 REPLACE( REPLACE( REPLACE(REPLACE([P ...

  9. Zookeeper核心机制

    (如果感觉有帮助,请帮忙点推荐,添加关注,谢谢!你的支持是我不断更新文章的动力.本博客会逐步推出一系列的关于大型网站架构.分布式应用.设计模式.架构模式等方面的系列文章) Zookeeper是Hado ...

  10. jquery.pagination.js分页插件的使用

    Pagination的相关参数: Pagination使用的核心代码:         //回调函数         function pageselectCallback(page_index, j ...