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 ...
随机推荐
- Text Template Transformation Toolkit
Text Template Transformation Toolkit 1.且算简介 笔者以一个英文字母和一个数字取了一个简单的名字.名唤"T4"(名 ...
- 3036: 绿豆蛙的归宿 - BZOJ
Description 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每 ...
- 【BZOJ】【2820】YY的GCD
莫比乌斯反演 PoPoQQQ讲义第二题. 暴力枚举每个质数,然后去更新它的倍数即可,那个g[x]看不懂就算了…… 为什么去掉了一个memset就不T了→_→…… /****************** ...
- uva 11825
刘书上例题 关于集合的动态规划 #include <cstdio> #include <cstdlib> #include <cmath> #include &l ...
- Unity3D研究院之IOS本地消息通知LocalNotification的使用
原地址:http://www.xuanyusong.com/archives/2632 现在的游戏里一般都会有本地消息,比如每天定时12点或者下午6点告诉玩家进入游戏领取体力.这种东西没必要服务器 ...
- java给图片加水印代码
try { String targetImg = "D:/Blue hills.jpg"; // String pressImg = "D:/20130311220300 ...
- 全球说:要给 OneAlert 点100个赞
客户背景 「全球说」 Talkmate,是北京酷语时代教育科技有限公司(酷语科技)旗下产品,酷语科技是一家诞生于中国的语言技术公司,致力于为全球用户提供一个全新的多语言学习和社交网络平台 . 全球说是 ...
- c# 在windows服务中 使用定时器
由于最近做自动执行的程序,开始做windows服务程序, 在windows服务中如何使用定时器的时候一直失效, 以前是直接拖入timer控件,但是不能直接运行,后来在网上找了一段程序,好使了. //开 ...
- C#中dynamic的正确用法 以及 typeof(DynamicSample).GetMethod("Add");
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性.比如,即使你 ...
- java二维码生成与解析代码实现
TwoDimensionCode类:二维码操作核心类 package qrcode; import java.awt.Color; import java.awt.Graphics2D; import ...