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

题意如下

研究人员有n种类型的砖块,每种类型的砖块都有无限个。第i块砖块的长宽高分别用xi,yi,zi来表示。 同时,由于砖块是可以旋转的,每个砖块的3条边可以组成6种不同的长宽高。你的任务是编写一个程序,计算猴子们最高可以堆出的砖块们的高度。

思路如下

我们先结合题目去分析这一题:题目中给了很多种块,而每种砖块的给了三个参数分别是 xi,hi,zi 三个参数中的每个参数都可以作为高,剩下两个参数中,可以任选其中一个作为长,最后剩下的那个参数作为宽,这样每种砖就可以衍生出6种砖,所以虽然每种砖无限个,但是我们却每种砖只能用一个(因为摆放砖块的时候是严格递减的),

这一题我们可以把这题转化成求 最大递减子序列的和,只不过这里的 和与原来所求的和(原来求和是:子序列中的元素的值直接相加,而我们这题的是 子序列的中每个元素(即代表 一个砖块

C - Monkey and Banana的更多相关文章

  1. hdu 1069 Monkey and Banana

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

  2. 杭电oj 1069 Monkey and Banana 最长递增子序列

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

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

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

  4. ACM-经典DP之Monkey and Banana——hdu1069

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  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(动态规划)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  7. Monkey and Banana(HDU 1069 动态规划)

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

  8. ZOJ 1093 Monkey and Banana (LIS)解题报告

    ZOJ  1093   Monkey and Banana  (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  9. HDU 1069 Monkey and Banana(DP 长方体堆放问题)

    Monkey and Banana Problem Description A group of researchers are designing an experiment to test the ...

  10. Monkey and Banana(基础DP)

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

随机推荐

  1. (26)ASP.NET Core EF保存(基本保存、保存相关数据、级联删除、使用事务)

    1.简介 每个上下文实例都有一个ChangeTracker,它负责跟踪需要写入数据库的更改.更改实体类的实例时,这些更改会记录在ChangeTracker中,然后在调用SaveChanges时会被写入 ...

  2. Java easyui 下拉框默认选中第一个

    html代码: <tr> <td> <div style="margin-bottom:5px">计价方式:   <%--下拉框默认选中第 ...

  3. python装饰器见解笔记

    def zsq(fun): def zsq_n(*args,**kwargs) print('这是装饰器需要运行内容') r = fun(*args,**kwargs) print('在被装饰函数执行 ...

  4. button控件根据文本自适应

    2020-03-12 每日一例第5天 1.添加按钮1和label.textbox控件,并修改相应的text值: 2.修改textBox1的TextChanged事件并输入代码: button1.Tex ...

  5. git 查看commit的提交记录

    相关命令: git log  查看所有提交记录 git show 查看提交详情 示例: git log: git show: 查看指定commit的详情:git show commitId 查看某次c ...

  6. celery订单定时回滚

    目录 订单回滚 控制执行(多少时间后执行) celery异步定时任务 订单回滚 用celery异步,定时任务.可以设置:如果下单15分钟后没有支付,则取消订单.做反向操作 控制执行(多少时间后执行) ...

  7. Oracle数据库使用sysdba登陆时出现ORA-01031: insufficient privileges问题

    今天在自己本本上装上了oracle数据库,然而在命令框登录时 用 sqlplus / as sysdba   时却出现了: insufficient privileges问题 原因就是没有加入ora_ ...

  8. 有关EPX Studio使用DELPHI5作为基础环境版本的说明

    英巴卡迪诺北京科技有限公司,地址是北京市朝阳门外大街18号丰联广场B座813B,这家公司这家公司不拥有:delphi 1.0~delphi7.0 .delphi 2005版本的著作权,这些都还是属于B ...

  9. 【Weiss】【第03章】练习3.16:删除相同元素

    [练习3.16] 假设我们有一个基于数组的表A[0,1...N-1],并且我们想删除所有相同的元素. LastPosition初始值为N-1,但应该随着相同元素被删除而变得越来越小. 考虑图3-61中 ...

  10. httpServletRequest.getCharacterEncoding()取出来是个null,怎么办?

    因为浏览器没有把正确的编码方式给服务器端. 目前,许多浏览器在Content-Type头中不会指定字符编码方式,那么容器就会使用"ISO-8859-1"方式解析POST数据,而此时 ...