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. Eight II HDU - 3567

    Eight II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 130000/65536 K (Java/Others)Total S ...

  2. javascript设计模式和开发实践(阶段一)

    1,设计模式的作用:让人们写出可复用和可维护性高的程序,代价可能是,额外增加代码量: 比较形象的例子:空房间里面放东西,如果日复一日的往里面扔东西,时间久了,很难找到自己想要的东西,调整也不容易,但是 ...

  3. Xcode调试之exc_bad_access以及 message sent to deallocated instance

    如果出现exc_bad_access错误,基本上是由于内存泄漏,错误释放,对一个已经释放的对象进行release操作.但是xcode有时候不会告诉你错误在什么地方(Visual Studio这点做得很 ...

  4. NSFileHandle的用法(用于读写文件)

    利用NSFilehandle类提供的方法,允许更有效地使用文件. 一般而言,处理文件时都要经历以下三个步骤: 1.打开文件,并获取一个NSFileHandle对象,以便在后面的I/O操作中引用该文件 ...

  5. arm 添加 ftp server 之 bftpd

    本来想装vsftp 结果装上以后执行报错 Segmentation fault , 换到几个 其它的小型ftp server 软件 ,试了 Stupid-FTPd,不能用. bftpd 可以使用,Ti ...

  6. django 从零开始 9 自定义密码验证加密

    先上想法,想对数据库账号的密码进行一个加密,但是django文档中的加密方法set_password貌似是只针对他们默认的user模型 或者继承 AbstractBaseUser的模型有效 from ...

  7. 01-if条件语句之数字比较

    if条件语句之数字比较 #!/bin/bash # 使用expr命令,比较结果正确,输入1,错误输入0 expr_mode(){ if [ $(expr $1 \<\= $2) -eq 1 ]; ...

  8. git重新学习

    一个学习网址:https://learngitbranching.js.org/ 一.对于一个新的远程空仓库 本地新建文件后推送 #初始化 git init #添加文件 git add README. ...

  9. Posix线程编程指南(4)

    Posix线程编程指南(4) 杨沙洲 原文地址:http://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ 线程终 ...

  10. java 泛型简介(转载)

    原文出处: absfree 1. Why ——引入泛型机制的原因 假如我们想要实现一个String数组,并且要求它可以动态改变大小,这时我们都会想到用ArrayList来聚合String对象.然而,过 ...