The Tower of Babylon
题意:
有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的更多相关文章
- UVa 437 The Tower of Babylon(经典动态规划)
传送门 Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details ...
- UVa 437 The Tower of Babylon
Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...
- UVA 437 十九 The Tower of Babylon
The Tower of Babylon Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- POJ2241——The Tower of Babylon
The Tower of Babylon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2207 Accepted: 1 ...
- UVA437-The Tower of Babylon(动态规划基础)
Problem UVA437-The Tower of Babylon Accept: 3648 Submit: 12532Time Limit: 3000 mSec Problem Descrip ...
- DAG 动态规划 巴比伦塔 B - The Tower of Babylon
题目:The Tower of Babylon 这是一个DAG 模型,有两种常规解法 1.记忆化搜索, 写函数,去查找上一个符合的值,不断递归 2.递推法 方法一:记忆化搜索 #include < ...
- HOJ 1438 The Tower of Babylon(线性DP)
The Tower of Babylon My Tags Cancel - Seperate tags with commas. Source : University of Ulm Internal ...
- uva The Tower of Babylon[LIS][dp]
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...
- [动态规划]UVA437 - The Tower of Babylon
The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many d ...
- UVa 437 The Tower of Babylon(DP 最长条件子序列)
题意 给你n种长方体 每种都有无穷个 当一个长方体的长和宽都小于还有一个时 这个长方体能够放在还有一个上面 要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法 比較不好控制 ...
随机推荐
- SNAT
http://blog.chinaunix.net/uid-2628744-id-2454879.html
- POJ 2407 Relatives(欧拉函数)
题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #includ ...
- jQuery从主页面存取控制 iframe 中的元素,参数及方法
从主页面上获取iframe下的某个对象,或使用iframe下的方法,或是获取iframe下某个doc元素,要求兼容各类浏览器,不仅仅ie; $(function() { $('#abgne_ifram ...
- jquery cookie 用法
jquery cookie 用法 $.cookie("name","value","options") 当不设置options时,此coo ...
- Bessie的体重问题
P1028 Bessie的体重问题 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 USACO OCT09 8TH 描述 Bessie像她的诸多姊妹一样,因 ...
- 李洪强漫谈iOS开发[C语言-038]-if else if语句
李洪强漫谈iOS开发[C语言-038]-if else if语句
- Spring3 报org.aopalliance.intercept.MethodInterceptor问题解决方法
原文:Spring3 报org.aopalliance.intercept.MethodInterceptor问题解决方法 一 开发环境:JDK5+Spring3.0.5+Myeclipse6.6+T ...
- 使用 Spring 3 来创建 RESTful Web Services(转)
使用 Spring 3 来创建 RESTful Web Services 在 Java™ 中,您可以使用以下几种方法来创建 RESTful Web Service:使用 JSR 311(311)及其参 ...
- UDP丢包和无序 问题的解决方法
最近在做一个项目,在这之前,做了个验证程序. 发现客户端连续发来1000个1024字节的包,服务器端出现了丢包现象. 纠其原因,是服务端在还未完全处理掉数据,客户端已经数据发送完毕且关闭了. 我用过s ...
- java web 下实现文件下载
来自:http://blog.csdn.net/longshengguoji/article/details/39433307 需求:实现一个具有文件下载功能的网页,主要下载压缩包和图片 两种实现方法 ...