poj2241 The Tower of Babylon
The Tower of Babylon
题意:给你n种石头,长x,宽y,高z,每种石头数目无限,一块石头能放到另一块上的条件是:长和宽严格小于下面的石头。问叠起来的最大高度。
/*
有些类似“叠箱子”问题,看起来一种砖有无限多个,其实最多只能用到两次。
说下我的思路吧,一块砖有3个数据,虽然3!=6,但本质上还是只有3种,把这三种都表示出来,使x<=y;这样就有了3n组数据。因为我不会建图,就把这3n组数据再排列一下,使一块砖只能放到它后面的砖之上,而绝不能放到之前的砖上,即按x为一级y为二级升序排列,结合之前的x<=y,就能达到目的了。
*/
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct
{
int arr[];
}Box;
Box a[];
bool cmp(Box a,Box b)
{
if(a.arr[]!=b.arr[])
return a.arr[] < b.arr[];
else if(a.arr[] != b.arr[])
return a.arr[] < b.arr[];
else return a.arr[] < b.arr[];
}
int ok(Box a,Box b)
{
return (a.arr[] < b.arr[] && a.arr[] < b.arr[]);
}
int main()
{
//freopen("Cola.in","r",stdin);
int n,m=,i,j,t,max;
while(cin>>n,n)
{
m++;
for(i = ; i < *n; i += )
{
cin>>a[i].arr[]>>a[i].arr[]>>a[i].arr[];
sort(a[i].arr,a[i].arr+);
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
a[i+].arr[] = a[i].arr[];
}
sort(a,a+*n,cmp);
max = ;
for(i = *n-; i >= ; i--)
{
t = a[i].arr[];
for(j = i+; j < *n; j++)
{
if(ok(a[i],a[j]) && a[i].arr[]+a[j].arr[] > t)
t = a[i].arr[]+a[j].arr[];
}
a[i].arr[] = t;
if(t > max) max = t;
}
printf("Case %d: maximum height = %d\n",m,max);
}
return ;
}
poj2241 The Tower of Babylon的更多相关文章
- POJ2241——The Tower of Babylon
The Tower of Babylon Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2207 Accepted: 1 ...
- 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 437 十九 The Tower of Babylon
The Tower of Babylon Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Subm ...
- UVA437-The Tower of Babylon(动态规划基础)
Problem UVA437-The Tower of Babylon Accept: 3648 Submit: 12532Time Limit: 3000 mSec Problem Descrip ...
- DAG 动态规划 巴比伦塔 B - The Tower of Babylon
题目:The Tower of Babylon 这是一个DAG 模型,有两种常规解法 1.记忆化搜索, 写函数,去查找上一个符合的值,不断递归 2.递推法 方法一:记忆化搜索 #include < ...
- HOJ 1438 The Tower of Babylon(线性DP)
The Tower of Babylon My Tags Cancel - Seperate tags with commas. Source : University of Ulm Internal ...
- uva The Tower of Babylon[LIS][dp]
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...
- [动态规划]UVA437 - The Tower of Babylon
The Tower of Babylon Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many d ...
随机推荐
- springMvc 4.0 jackson包改变
使用之前的json包出包java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException错误. sp ...
- linux日常开发使用命令整理
linux: 安装ssh-server:$ sudo apt-get install openssh-server 更新软件库:$ sudo apt-get update 启动ssh:$ sudo / ...
- 【转】Java中的代码点与代码单元
转载自:http://blog.csdn.net/xujinsmile/article/details/8526387 最近看core java,之前一直不明白,看了不少帖子和博客,总算搞明白了. J ...
- Ajax处理后台返回的Json数据
// 处理后台传来的Json字符串装换成Json对象 var dataJson = JSON.parse(data); // 此时可以从Json对象中取值 if(dataJson.result == ...
- wingide 显示中文 及 配色方案
http://lihuipeng.blog.51cto.com/3064864/923231 网上收集的方法: 显示中文: 任意文本编辑器打开:x:\Wing IDE\bin\gtk-bin\etc\ ...
- k8s-flannel容器集群网络部署
[root@k8s-master src]# wget https://github.com/coreos/flannel/releases/download/v0.9.1/flannel-v0.9. ...
- android如何查看网卡名和ip
我们知道,在windows下查看ip地址用ipconfig,在Linux下查看ip地址用ifconfig.今天在使用android查看的时候ifconfig却不管用: 查找网上资料发现,原来默认ifc ...
- 「LuoguP4995」「洛谷11月月赛」 跳跳!(贪心
题目描述 你是一只小跳蛙,你特别擅长在各种地方跳来跳去. 这一天,你和朋友小 F 一起出去玩耍的时候,遇到了一堆高矮不同的石头,其中第 ii 块的石头高度为 h_ihi,地面的高度是 h_0 = 0 ...
- ACM学习历程—ZOJ3471 Most Powerful(dp && 状态压缩 && 记忆化搜索 && 位运算)
Description Recently, researchers on Mars have discovered N powerful atoms. All of them are differen ...
- Trie 树内存消耗问题
大家都知道,Trie树(又称字典树)是一种树型数据结构,用于保存大量的字符串.它的优点是:利用字符串的公共前缀来节约存储空间. 相对来说,Trie树是一种比较简单的数据结构,比较易于理解.话说上帝是公 ...