HDU 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
Sample Output
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int dp[];
struct node
{
int a,b,c;
}d[]; bool cmp(const node x,const node y)
{
if(x.a==y.a)
return x.b>y.b;
return x.a>y.a;
}
int main()
{
int n,Case=;
while(scanf("%d",&n)&&n)
{
int a,b,c;
for(int i=;i<n;i++)
{
scanf("%d%d%d",&a,&b,&c);
if(a>b) swap(a,b);
if(a>c) swap(a,c);
if(b>c) swap(b,c);
d[*i].a=a;
d[*i].b=b;
d[*i].c=c;
d[*i+].a=a;
d[*i+].b=c;
d[*i+].c=b;
d[*i+].a=b;
d[*i+].b=c;
d[*i+].c=a;
}
sort(d,d+*n,cmp);
int res=;
memset(dp,,sizeof(dp));
for(int i=;i<*n;i++)
dp[i]=d[i].c;///防止d[0~i-1]没有一个长宽均大于d[i],这时给它自己本身高度;
for(int i=;i<*n;i++)
{
for(int j=;j<i;j++)
{
if(d[j].a>d[i].a&&d[j].a&&d[j].b>d[i].b)
dp[i]=max(dp[i],dp[j]+d[i].c);
}
res=max(res,dp[i]);
}
printf("Case %d: maximum height = %d\n",Case++,res);
}
return ;
}
HDU 1069---背包---Monkey and Banana的更多相关文章
- HDU 1069:Monkey and Banana(DP)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 【HDU - 1069】 Monkey and Banana (基础dp)
Monkey and Banana 直接写中文了 Problem Statement 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子 ...
- hdu 1069 (DP) Monkey and Banana
题目:这里 题意: Description 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块 ...
- 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 / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- (最大上升子序列)Monkey and Banana -- hdu -- 1069
http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit:1000MS Memory L ...
- 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
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- Unity5网络模块UNet介绍
前段时间,研究了一下UNet,经过项目实践,大致整理了下遇到的问题. 源码Bitbucket:需要说明的是,这个项目只包含上层的包装,一些低层的网络实现在Unity内部,如NetworkTranspo ...
- 大型网站系统架构演化之路【mark】
前言 一 个成熟的大型网站(如淘宝.天猫.腾讯等)的系统架构并不是一开始设计时就具备完整的高性能.高可用.高伸缩等特性的,它是随着用户量的增加,业务功能的 扩展逐渐演变完善的,在这个过程中,开发模式. ...
- 如何通过XShell传输文件
转载孟光孟叔的博客: https://learndevops.cn/index.php/2016/06/14/how-to-transfer-file-using-xshell xshell目前最好 ...
- WindowsServer2012桌面图标设置
1.win+R调出运行窗口 2.输入:rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0 即可
- EF执行存储过程时超时问题
异常信息:Message = EF "Timeout 时间已到.在操作完成之前超时时间已过或服务器未响应." ((IObjectContextAdapter);
- c与c++中的extern const的区别和联系
最近复习c++,发现了这个东西. c语言里面,我们在一个.c文件中用const定义了一个全局变量后,可以在另一个.c文件中用extern const来引用,但在c++中在链接的时候会报undefine ...
- python 教程_【python 基础教程详解】
Lesson 1 准备好学习Python的环境下载的地址是:www.python.org为了大家的方便,我在校内作了copy:http://10.1.204.2/tool/compiler&I ...
- Go语言实现HashSet
set.go // set project set.go package set type Set interface { Add(e interface{}) bool Remove(e inter ...
- 【Thinking in Java-CHAPTER 3】操作符
优先级 赋值 对象在使用c=d,那么c和d都指向原本只有d指向的那个对象. 方法调用中的别名问题:当一个对象作为参数传递到一个函数中,函数改变了这个参数,则改变了传递进来的对象: 自增和自减 浮点型的 ...
- PLSQL快捷补充代码设置
菜单Tools-->Preferences...然后依次选择下图红色选项 弹出下图对话框 输入需要快速生成的语句点击保存 点击Save后在slq窗口中输入 设置的语句缩写 列入:第一个sf 然 ...