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 ...
随机推荐
- WPF 多线程处理(1)
WPF 多线程处理(1) WPF 多线程处理(2) WPF 多线程处理(3) WPF 多线程处理(4) WPF 多线程处理(5) WPF 多线程处理(6) 废话不多说,先上图: 多线程处理数据后在th ...
- Smarty插件简单开发
smarty的插件相当简单,你的网站经常会用到一些特定的Url或Controller或Action的路由地址的动态生成,通过smarty插件方式可以很轻松的实现. 在smarty/plugins目录下 ...
- "Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b7
1.错误背景 系统安装了.net framework4.0.4.5,项目先使用VS2013(4.5)开发,后来又重新用VS2010开发(4.0),运行时出现这个错误 2.错误原因 In .Net 4. ...
- Asp.Net原理Version3.0_页面声明周期
Asp.Net原理Version1.0 Asp.Net原理Version2.0 相关源码 页面的Process方法 // System.Web.UI.Page pr ...
- C#中两个日期类型相减得到天数
protected int GetDuration(DateTime start, DateTime finish) { return (finish - start).Days; } 直接相减得到的 ...
- jquery(1.3.2)<--json-->spring(3.0)
发现spring 3已经对ajax支持的很好了,前端可以只使用html+jquery,后端 只使用spring再加上一种orm,两者之间用json交换数据就可以了,现在是放弃 jsp,struts这些 ...
- 使用静态变量的方法求n!
下面的程序可以输出1-5的阶乘值,如果需要把5改为n,则可求出1-n的阶乘值. void main() { setvbuf(stdout,NULL,_IONBF,); int fac(int n); ...
- C/C++框架和库
http://blog.csdn.net/xiaoxiaoyeyaya/article/details/42541419 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在 ...
- POJ1442Black Box
http://poj.org/problem?id=1442 题意 : 题目中对给出的数字有两种操作ADD(I)操作,将ADD括号里的数字 I 加到数列里边去,然后是自动排好序的,每一个数列前边都会有 ...
- SQL server 复习一
第一天 下面我们从最基础的开始: 在运行里面输入:services.msc 一.启动服务 二.数据库登录的两种身份验证方式 另外一种身份验证方式就是SQL Server身份验证. sa不能使用的时候可 ...