HDU 1069

Description

A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block on the top another to build a tower and climb up to get its favorite food.

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

The input file will contain one or more test cases. The first line of each test case contains an integer n, 
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

For each test case, print one line containing the case number (they are numbered sequentially starting from 1) and the height of the tallest possible tower in the format "Case case: maximum height = height". 
 

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
 
代码如下:
#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的更多相关文章

  1. HDU 1069:Monkey and Banana(DP)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. 【HDU - 1069】 Monkey and Banana (基础dp)

    Monkey and Banana 直接写中文了 Problem Statement 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子 ...

  3. hdu 1069 (DP) Monkey and Banana

    题目:这里 题意: Description 一组研究人员正在设计一项实验,以测试猴子的智商.他们将挂香蕉在建筑物的屋顶,同时,提供一些砖块给这些猴子.如果猴子足够聪明,它应当能够通过合理的放置一些砖块 ...

  4. HDU 1069 Monkey and Banana(二维偏序LIS的应用)

    ---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  5. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. 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 ...

  7. (最大上升子序列)Monkey and Banana -- hdu -- 1069

    http://acm.hdu.edu.cn/showproblem.php?pid=1069      Monkey and Banana Time Limit:1000MS     Memory L ...

  8. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

  9. hdu 1069 动规 Monkey and Banana

     Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. C# 接口的隐式与显示实现

    隐式实现的话实现的方法属于实现的类的,可以直接通过类的对象访问,显式实现的话方法是属于接口的,可以看成是寄托在类中实现的,访问这些方法时要先把对象转换成接口对象,然后通过接口对象调用 一般来讲显式实现 ...

  2. .Net事件管道详解图

  3. 【Cocos2d-Js基础教学(7)界面UI更新方法(会用到第三方类库)】

    我们游戏中会遇到很多UI更新的时候,大部分时候我们会remove该节点,再重新绘制的方法来进行UI更新. 但是这种更新效率并不高,这里我推荐大家一个第三方的库,来通过注册更新的方式来对UI进行更新管理 ...

  4. Carthage 安装和使用

    和Cocoapods相比各有利弊吧,具体对比参见: Carthage 初探:四大优势与四大劣势 第一步:如果没有安装Homebrew先安装 打开命令终端,直接输入以下命令回车 /usr/bin/rub ...

  5. Silverlight:版本控制的衍化

    版本控制是企业开发中一个老生长谈的主题,这也是大部分公司新人进来后需要接纳的一个基础知识体系. 从08年首次接触商业软件编写后,这几年先后接触了SVN,TFS,Git这几个主要的版本控制器,但是并没有 ...

  6. [初读笔记] Cloud Migration Research: A Systematic Review (TCC, 2013)

    Pooyan Jamshidi, Aakash Ahmad, Claus Pahl, "Cloud Migration Research: A Systematic Review," ...

  7. 优化IIS7.5支持10万个同时请求windows 2008 R2

    通过对IIS7的配置进行优化,调整IIS7应用池的队列长度,请求数限制,TCPIP连接数等方面,从而使WEB服务器的性能得以提升,保证WEB访问的访问流畅. -

  8. 微信公众号API返回不可打印字符的处理。

    引言 在使用微信公众号的"批量获取用户基本信息"API时,发现在某些时候不能使用php的json_decode转为数组,打印出curl获取到的内容中,发现了几个不可打印字符.相信不 ...

  9. hdinfo

    --------[ 鲁大师 ]-------------------------------------------------------------------------------- 版本: ...

  10. CM: 如何自己build一个官方版本出来,使用官方release中的manifests.xml

    This can be accomplished in one of two ways: 1) Pull the file from your device:cd /your/repo/pathadb ...