UVA 437 十九 The Tower of Babylon
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
System Crawler (2015-08-29)
Description
Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:
The babylonians had n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions . A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height. They wanted to construct the tallest tower possible by stacking blocks. The problem was that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the babylonians can build with a given set of blocks.
Input and Output
The input file will contain one or more test cases. The first line of each test case contains an integer n, representing the number of different blocks in the following data set. The maximum value for n is 30. Each of the next n lines contains three integers representing the values ,
and
.
Input is terminated by a value of zero (0) for n.
For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Casecase: maximum height =height"
Sample Input
1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; struct Node
{
int l;
int r;
int h;
int s;
}; Node a[]; bool cmp(Node p,Node q)
{
return p.s<q.s;
} int main()
{
int N,n;
int i,j,k=;
int dp[];
while(scanf("%d",&N)!=EOF && N!=)
{
n=;
memset(dp,,sizeof(dp));
for(i=;i<=N;i++)
{
int x,y,z;
scanf("%d %d %d",&x,&y,&z);
n++;
a[n].l=max(x,y),a[n].r=min(x,y),a[n].h=z,a[n].s=x*y;
n++;
a[n].l=max(x,z),a[n].r=min(x,z),a[n].h=y,a[n].s=x*z;
n++;
a[n].l=max(z,y),a[n].r=min(z,y),a[n].h=x,a[n].s=z*y;
} sort(a+,a+n+,cmp);
dp[n]=a[n].h;
int ans=dp[n];
for(i=n-;i>=;i--)
{
int max=;
for(j=i+;j<=n;j++)
{
if(a[i].l<a[j].l && a[i].r<a[j].r && dp[j]>max)
max=dp[j];
}
dp[i]=max+a[i].h;
if(dp[i]>ans)
ans=dp[i];
} printf("Case %d: maximum height = %d\n",k++,ans);
}
return ;
}
UVA 437 十九 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(DP 最长条件子序列)
题意 给你n种长方体 每种都有无穷个 当一个长方体的长和宽都小于还有一个时 这个长方体能够放在还有一个上面 要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法 比較不好控制 ...
- uva The Tower of Babylon[LIS][dp]
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...
- UVA The Tower of Babylon
The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many det ...
- 「kuangbin带你飞」专题十九 矩阵
layout: post title: 「kuangbin带你飞」专题十九 矩阵 author: "luowentaoaa" catalog: true tags: mathjax ...
- 无废话ExtJs 入门教程十九[API的使用]
无废话ExtJs 入门教程十九[API的使用] extjs技术交流,欢迎加群(201926085) 首先解释什么是 API 来自百度百科的官方解释:API(Application Programmin ...
- Python之路【第十九章】:Django进阶
Django路由规则 1.基于正则的URL 在templates目录下创建index.html.detail.html文件 <!DOCTYPE html> <html lang=&q ...
- Bootstrap <基础二十九>面板(Panels)
Bootstrap 面板(Panels).面板组件用于把 DOM 组件插入到一个盒子中.创建一个基本的面板,只需要向 <div> 元素添加 class .panel 和 class .pa ...
随机推荐
- 夺命雷公狗ThinkPHP项目之----企业网站23之网站前台二级分类的跳转(URL跳转到列表页或产品页)
我们现在开始做实现我们的二级菜单如何跳转到指定的列表页或者产品也呢?? 我们分享下数据库情况: 我们的数据库里提前给我们预留了一个cate_type的字段,那么我们可以让这个字段进行判断,从而遍历出指 ...
- android初体验——HelloWord
一.新建项目: 打开 eclipse ,选择File – New – Android Application Project 输入项目名称,程序名称,包名. 包名不能重复,它是项目的唯一标示,我理解为 ...
- Another app is currently holding the yum lock; waiting for it to exit...另一个应用程序在占用yum lock,等待其退出。
这种情况下通常是由于yum的时候意外退出造成的,虽然也给出提示当前占用进行的id,但是执行kill -9 3599 强制杀死进程后,情况依然没能改变. 备注:(-9是强制杀死) 主要原因是因为,yum ...
- yii2表关联实例
yii2表关联 1.两张表关联,以“商品表关联品牌表”为例 控制器中: $goods_model=new Goods(); $goods_info=$goods_model::find()->j ...
- URL 中#号,? ,&的作用 (摘抄整理 链接为学习地址)
1. 一峰的网络日志:http://www.ruanyifeng.com/blog/2011/03/url_hash.html get: 1.页面滚动到指定页面的指定位置 (eg: http://ww ...
- DButil
纲要: Properties prop = new Properties(); BasicDataSource ds = new BasicDataSorce(); Connection conn = ...
- OBD 14230 Slow, Addr激活
const u8 LinkCmd14230[6] = { 0xC2, 0x33, 0xF1, 0x01, 0x00, 0xE7 }; u8 ISO14230ADDR_Check(){ ...
- javaWeb 使用jsp标签进行防盗链
/** * 1.新建类继承SimpleTagSupport * 新建2个属性, 添加对应的set方法 * 覆盖doTag()方法 */ import java.io.IOException; impo ...
- c#使用word、excel、pdf ——转
一.C# Word操作引入Word COM组件菜单=>项目=>添加引用=>COM=>Microsoft Word 11.0 Object Libraryusing Word = ...
- iOS直播的技术分析与实现
HTTP Live Streaming直播(iOS直播)技术分析与实现 发布于:2014-05-28 13:30阅读数:12004 HTTP Live Streaming直播(iOS直播)技术分析与实 ...