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 ...
随机推荐
- python学习之“切片操作从入门到精通”
在python学习开发的过程中,我们总是不断的要对List(列表),Tuple(元组)有取值操作:假如我们有一个列表List1现在想取出1其中的前5个元素,改怎么操作呢? >>> L ...
- oracle——merge
一.概述 使用merge声明从一个或者更多个表或视图中筛选记录,以用来更新或者插入到一个表或视图中.你可以指定条件以决定是执行update操作还是insert操作到目标表或视图中. 这个声明是一个 ...
- ios开发之网络基础
1.网络访问的步骤 1> 建立NSURL 2> 建立NSURLRequest 3> 建立NSURLConnection 4> 开始连接 - (void)viewDidLoad ...
- 有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面m个数。
#include<stdio.h> #include<stdlib.h> int main() { setvbuf(stdout,NULL,_IONBF,); //使用Ecli ...
- uva 1056
floyd 算法 用了stl 的map 存名字的时候比较方便 #include <cstdio> #include <cstdlib> #include <cmath&g ...
- 暑假集训单切赛第一场 CF 191A Dynasty Puzzles
题意不说了,看原题吧,思路见代码: #include <iostream> #include <stdio.h> #include <string.h> #incl ...
- 淘宝(taobao)HSF框架
一.背景 随着网站访问量增加,仅仅靠增加机器已不能满足系统的要求,于是需要对应用系统进行垂直拆分和水平拆分.在拆分之后,各个被拆分的模块如何通信?如何保证 性能?如何保证各个应用都以同样的方式交互?这 ...
- Netty 的Downstream 和 Upstream
Netty的Downstream 和 Upstream 如果一个event从第一个handler传递直到最后一个handler就是 Upstream 相反的如果一个event从最后一个handler传 ...
- 通过一个简单的数据库操作类了解PHP链式操作的实现
class Model{ public $table; //操作的表; private $opt; //查询的参数; private $pri; //表的主键; private $lastSql; / ...
- 【Linux高频命令专题(4)】sed
简述 sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法 sed命令行格式为: sed [-ne ...