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 ...
随机推荐
- Java for LeetCode 106 Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Total Accepted: 31041 Total Submissions: ...
- oracle ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor 1.看看是不是监听 ...
- Android Weekly Notes Issue #316
July 1st, 2018 Android Weekly Issue #316 本期内容包含教你使用Kotlin通过Annotation Processor生成代码文件, JetPack中的Andr ...
- BZOJ 3362 Navigation Nightmare
一道带权并查集题目. 带权并查集的重点是信息的合并. 这类题出现得并不多,练习一下. #include<bits/stdc++.h> using namespace std; #defin ...
- [HDU4609] 3-idiots FFT+计数
用FFT再去重计算出两条边加起来为某个值得方案数,然后用总方案数减去不合法方案数即可. #include<iostream> #include<cstdio> #include ...
- Contiki源码结构
Contiki源码结构 apps目录下,用于存放Application,也就是我们的应用程序放在这个目录下.如webserver,webrowser等,如下图所示. core目录是contiki操作系 ...
- BZOJ3991:寻宝游戏 (LCA+dfs序+树链求并+set)
小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然后可以任意在地图的道路上行走 ...
- MySQL 单笔订单满6个及以上产品且金额>=300赠送优惠券_20161103
活动内容: 单笔订单满6个及以上产品(帽子.浴巾除外),金额满赠300元,即赠送300-10元(除帽子.浴巾外)优惠券一张.需求数据:满足条件的用户ID活动时间:11.2-11.5(4天)活动规则:① ...
- codevs 3049 舞蹈家怀特先生
题目描述 Description 怀特先生是一个大胖子.他很喜欢玩跳舞机(Dance Dance Revolution, DDR),甚至希望有一天人家会脚踏“舞蹈家怀特先生”.可惜现在他的动作根本不能 ...
- WPF Background的设置有坑
今天帮忙同事解决在后台绑定时,动态更改控件(Grid)的Background. 有个陷阱,C#有2个命名空间有Brush和Color, 分别为System.Drawing和System.Window. ...