杭电 1069 Monkey and Banana
Description
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
Input
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
Output
Sample Input
1
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
经典的dp问题,刚开始接触有点难度
给出n种类型的长方体石块,给出每种的长宽高,每种石块有三种摆放方式,数量不限,可以累加着往上放,问最多能放多高
但是有个限定条件,长和宽必须均小于下面石块的长和宽才能放上去
转换成dp模型,就是dp[i]表示放置到第i个石块最高的高度,上面石块边长必须严格小于下面石块
#include<cstdio>
#include<algorithm>
using namespace std;
struct stu
{
int l,w,h;
}st[];
bool cmp(stu a,stu b) //从顶往下判断所以从小往大排序
{
if(a.l != b.l)
return a.l < b.l;
else
return a.w < b.w;
}
int main()
{
int k=;
int dp[]; //dp[i]表示从顶开始到第i个木块的高度
int n,a,b,c,max0,num;
while(scanf("%d",&n) && n)
{
int i,j;
num=;
for(i = ; i <= n ; i++)
{
scanf("%d %d %d",&a,&b,&c);
st[num].l=a,st[num].w=b,st[num++].h=c; //每个木块有三种放法
st[num].l=a,st[num].w=c,st[num++].h=b;
st[num].l=b,st[num].w=a,st[num++].h=c;
st[num].l=b,st[num].w=c,st[num++].h=a;
st[num].l=c,st[num].w=a,st[num++].h=b;
st[num].l=c,st[num].w=b,st[num++].h=a;
}
sort(st,st+num,cmp);
for(i = ; i < num ; i++)
{
dp[i]=st[i].h;
}
for(i = ; i < num ; i++)
{
for(j = ; j < i ; j++)
{
if(st[j].l < st[i].l && st[j].w < st[i].w && dp[j]+st[i].h > dp[i])
{
dp[i]=dp[j]+st[i].h;
}
}
}
sort(dp,dp+num);
printf("Case %d: maximum height = ",k++);
printf("%d\n",dp[num-]);
}
return ;
}
杭电 1069 Monkey and Banana的更多相关文章
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 杭电oj 1069 Monkey and Banana 最长递增子序列
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1069 Monkey and Banana
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1069 Monkey and Banana(动态规划)
Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...
随机推荐
- 让VS2010也支持html5和css3语法验证
让VS2010也支持html5和css3语法验证 步骤: 首先打开VS2010或者可自行下载均可,我这里是利用VS的扩展器 弹出如下画面,然后选在,联机库,在右上角输入css3,即可看到下面,然后选中 ...
- deque双向队列
对于双向队列,与队列queue以及vector容器的区别就在于,名字不同,也就是它是双向的,可以从头开始操作,也可以从末尾开始操作. 双向队列的常用方法跟队列queue差不多: 头文件: #inclu ...
- UWP 页面跳转传值
如果涉及到页面跳转,一般用Frame这个控件来管理不同的页面. <Grid Name="RootGrid"> <Frame Name="RootFram ...
- LBP特征
此篇摘取 <LBP特征原理及代码实现> <LBP特征 学习笔记> 另可参考实现: <LBP特征学习及实现> <LBP特征的实现及LBP+SVM分类> & ...
- 接口测试01 - HTTP协议报文结构及示例
HTTP基本架构 用一张简单的流程图来展示HTTP协议的基本架构,以便先有个基础的了解. 1)Web Client可以是浏览器.搜索引擎等等一切基于HTTP协议发起http请求的工具. 2)Web S ...
- 万能makefile模板
这里一份万能makefile模板,写opencv项目时候使用的. 前提是提前配置好 包管理工具 pkg 然后就不用每次都去 -lopencv_xxx了. ####################### ...
- [已读]web性能实践日志
书是在今年5月份出版,但是书中的内容是发表于11年到12年之间的,如果知道这一点,我一定不会买~ 列举一下大致内容: YSlow localStroage读取数据最佳策略 性能优化各种策略(图片精灵 ...
- mybatis javaConfig实现
@Bean public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { SqlSessio ...
- AJPFX总结面向对象(this和super的区别和应用)
面向对象(this和super的区别和应用)(掌握)* A:this和super都代表什么 * this:代表当前对象的引用,谁来调用我,我就代表谁 * super:代表当 ...
- [ SNOI 2013 ] Quare
Description 题目链接 求一张无向带权图的边双连通生成子图的最小代价. Solution 核心的思路是,一个点双连通分量肯定是一堆环的并. 考虑增量地构造这个边双连通图,每次把一个环并进去, ...