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 ...
随机推荐
- C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X
//加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...
- 【转】使用JIRA搭建企业问题跟踪系统【个人推荐】
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:Judy Shen的专栏 原文地址:使用JIRA搭建企业问题跟踪系统 ...
- DevExpress控件使用系列--ASPxTreeList
控件功能 结合列表控件及树控件的优点,在列表控件中实现类型树的多层级操作 官方说明 http://documentation.devexpress.com/#AspNet/clsDevExpres ...
- 【转】2-SAT题集
转自:http://blog.csdn.net/shahdza/article/details/7779369 [HDU]3062 Party1824 Let's go home3622 Bomb G ...
- pureftpd安装配置-pureftp参数详解(一)
1. 下载 #cd /usr/local/src/ #wget ftp://ftp.pureftpd.org/pub/pure-ftpd/releases/pure-ftpd-1.0.30.tar.g ...
- ios开发之多线程资源争夺
上一篇介绍了常用的多线程技术,目前开发中比较常用的是GCD,其它的熟悉即可.多线程是为了同步完成多项任务,不是为了提高运行效率,而是为了提高资源使用率来提高系统的整体性能,但是会出现多个线程对同一资源 ...
- PHP创建XML文件讲解
<?php #code by coder_apex 2007-6-15 #自动生成一个如下的XML文件 # # <?xml version="1.0& ...
- POJ 2255 Tree Recovery(根据前序遍历和中序遍历,输出后序遍历)
题意:给出一颗二叉树的前序遍历和中序遍历的序列,让你输出后序遍历的序列. 思路:见代码,采用递归. #include <iostream> #include <stdio.h> ...
- 深入浅出ES6(四):模板字符串
作者 Jason Orendorff github主页 https://github.com/jorendorff 反撇号(`)基础知识 ES6引入了一种新型的字符串字面量语法,我们称之为模板字符 ...
- React vs Angular 2: 冰与火之歌
黄玄 · 3 个月前 本文译自 Angular 2 versus React: There Will Be Blood ,其实之前有人翻译过,但是翻得水平有一点不忍直视,我们不希望浪费这篇好文章. 本 ...