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 ...
随机推荐
- Pro ASP.NET MVC –第四章 语言特性精华
C#语言有很多特性,并不是所有的程序员都了解本书我们将会使用的C#语言特性.因此,在本章,我们将了解一下作为一个好的MVC程序员需要了解C#语言的特性. 每个特性我们都只是简要介绍.如果你想深入了解L ...
- SQL SERVER 服务启动后停止,某些服务由其它服务或程序使用时将自动停止
发生症状: 先是服务器挂掉,之后服务器可以登陆,但是实例却不能登陆进去(部分).出现的错误日志如下: :: R2 (SP2) - 10.50.4000.0 (X64) Jun :: Copyright ...
- c#上iOS apns p12文件制作记录
1.在桌面上建一个"apns_p12"文件夹,所有的保存和生成文件都放在这里 2.从钥匙串中生成CertificateSigningRequest.certSigningReque ...
- PHP读写文件高并发处理实例-转
背景: 最近公司游戏开发需要知道游戏加载的流失率.因为,我们做的是网页游戏.玩过网页游戏的人都知道,进入游戏前要加载一些资源.最后才能到达创建角色的游戏界面.我们有一个需求就是要统计在加载过程中还未到 ...
- SASS用法指南-转
作者: 阮一峰 日期: 2012年6月19日 原文地址:http://www.ruanyifeng.com/blog/2012/06/sass.html 艹,没想到sass 2012年就有了.现在 ...
- 我的首个MOOC课程《面向对象软件开发实践》
我的首个MOOC课程<面向对象软件开发实践> 我将在网易云课堂开讲MOOC课<面向对象软件开发实践>(http://mooc.study.163.com/course/YOOK ...
- 使用IntelliJ IDEA 14和Maven创建java web项目
参考地址 http://www.cnblogs.com/jifeng/p/4658765.html
- sitemesh2在tomcat和weblogic中同时使用的配置问题
(一)拦截*.do,装饰器中匹配do tomcat 可行 weblogic 不可行 web.xml ~~~ <filter> <filter-name>sitemesh< ...
- [原]如何用Android NDK编译FFmpeg
我们知道在Ubuntu下直接编译FFmpeg是很简单的,主要是先执行./configure,接着执行make命令来编译,完了紧接着执行make install执行安装.那么如何使用Android的ND ...
- solrcloud使用中遇到的问题及解决方式
首先声明,我们团队在使用solrcloud过程中踩了一些坑,同事(晓磊和首富)进行了总结,我列到我的博客上做记录用: Q:为什么Solr里面的时间比数据库里面早8小时? Solr默认采用的时区是UTC ...