UVa 437 (变形的LIS) The Tower of Babylon
题意:
有n种类型的长方体,每种长方体的个数都有无限个。当一个长方体的长和宽分别严格小于另一个长方体的长和宽的时候,才可以把这个放到第二个上面去。输出这n种长方体能组成的最大长度。
分析:
虽说每种都有无限个,可每种长方体一共的“姿态”最多也只有三种,将它们三个边长分别作为高。然后按照底面排序,就转化为最大上升子列的问题。
代码中采用了“人人为我”的方法。
//#define LOCAL
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = ;
struct Cube
{
int x, y, z;
bool operator< (const Cube& a) const
{ return x < a.x || (x == a.x && y < a.y); }
}cubes[maxn];
int size[], dp[maxn]; bool check(int a, int b)
{
return (cubes[a].x < cubes[b].x && cubes[a].y < cubes[b].y);
} int main(void)
{
#ifdef LOCAL
freopen("437in.txt", "r", stdin);
#endif int n, kase = ;
while(scanf("%d",&n) == && n)
{
for(int i = ; i < n; ++i)
{
for(int j = ; j < ; ++j) scanf("%d", &size[j]);
sort(size, size + );
cubes[i*].x = size[], cubes[i*].y = size[], cubes[i*].z = size[];
cubes[i*+].x = size[], cubes[i*+].y = size[], cubes[i*+].z = size[];
cubes[i*+].x = size[], cubes[i*+].y = size[], cubes[i*+].z = size[];
}
n *= ;
sort(cubes, cubes + n);
memset(dp, , sizeof(dp));
for(int i = ; i < n; ++i) dp[i] = cubes[i].z;
for(int i = ; i < n; ++i)
for(int j = ; j < i; ++j)
if(check(j, i)) dp[i] = max(dp[i], cubes[i].z + dp[j]);
int ans = ;
for(int i = ; i < n; ++i) ans = max(ans, dp[i]);
printf("Case %d: maximum height = %d\n", ++kase, ans);
} return ;
}
代码君
UVa 437 (变形的LIS) The Tower of Babylon的更多相关文章
- UVA 437 十九 The Tower of Babylon
The Tower of Babylon Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- 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 The Tower of Babylon[LIS][dp]
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...
- UVa 437 The Tower of Babylon(DP 最长条件子序列)
题意 给你n种长方体 每种都有无穷个 当一个长方体的长和宽都小于还有一个时 这个长方体能够放在还有一个上面 要求输出这样累积起来的最大高度 由于每一个长方体都有3种放法 比較不好控制 ...
- UVA The Tower of Babylon
The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many det ...
- POJ 2241 The Tower of Babylon
The Tower of Babylon Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Or ...
- 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 ...
随机推荐
- 关于sublime text的配置方法
一个星期没有写博客了, 是时候来一波了 -------------------------------------------------------------------------------- ...
- python 链接hive
http://blog.csdn.net/xubcing/article/details/8350287 http://www.centoscn.com/python/2014/0921/3801.h ...
- 设计模式之单实例模式(Singleton)
原理:将类的构造函数由pubic变为private或者protect,添加获取对象的public 成员函数,返回指向对象的静态指针. 首先来一段简单的代码实现 代码一 class Singleton ...
- 《head first java 》读书笔记(三)
Updated 2014/04/03 --P518 Thread需要任务,任务是实现过Runnable的实例.Runnalbe这个接口只有一个方法.run()会是新线程所执行的第一项方法.要把Runn ...
- android 解析XML方式(一)
在androd手机中处理xml数据时很常见的事情,通常在不同平台传输数据的时候,我们就可能使用xml,xml是与平台无关的特性,被广泛运用于数据通信中,那么在android中如何解析xml文件数据呢? ...
- Unity3D Development模式下的一个小问题
今天客户提交了一个反馈,说测试版本的应用在按下电源键的时候屏幕变黑,然后重新按下电源键启动的时候发现没有出现屏幕锁屏的情况,直接回到应用界面. 我这边看了一下,发现如果装了360之类的手机助手就没这个 ...
- MongoDB 性能优化五个简单步骤
MongoDB 一直是最流行的 NoSQL,而根据 DB-Engines Ranking 最新的排行,时下 MongoDB 已经击败 PostgreSQL 跃居数据库总排行的第四位,仅次于 Oracl ...
- (int)、Convert.ToInt32()与int.Parse()的区别
1.(int)是类型转换,能够使用(int)进行强类型转换的只能是数值类型,如long.short.double等,这种转换时需要考虑精度问题. 如下的代码就行不通了: string text = & ...
- Amazon 面经
[版面:待字闺中][首篇作者:gmadj] , 2013年09月29日21:51:33 [首页] [上页][下页][末页] [分页:1 2 ] gmadj 进入未名形象秀 我的博客 [回复] ...
- android音乐播放器开发教程
android音乐播放器开发教程 Android扫描sd卡和系统文件 Android 关于录音文件的编解码 实现米聊 微信一类的录音上传的功能 android操作sdcard中的多媒体文件——音乐列表 ...