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. python之嵌套 闭包 装饰器 global、nonlocal关键字

    嵌套: 在函数的内部定义函数闭包: 符合开放封闭原则:在不修改源代码与调用方式的情况下为函数添加新功能  # global 将局部变量变成全局变量 num = 100 def fn1(): globa ...

  2. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

  3. MATLAB中的Regex

    regexprep——用于对字符串进行查找并替换. regexp Definition: 用于对字符串进行查找,大小写敏感. startIndex = regexp(str,expression) 返 ...

  4. Vue2.0 【第一季】第5节 v-on:绑定事件监听器

    目录 Vue2.0 [第一季] 第5节 v-on:绑定事件监听器 第五节 v-on:绑定事件监听器 一.使用绑定事件监听器,编写一个加分减分的程序. Vue2.0 [第一季] 第5节 v-on:绑定事 ...

  5. LeetCode(239.滑动窗口的最大值

    题目: 给定一个数组nums,有一个大小为k的滑动窗口从数组的最左侧移动到最右侧,你只可以看到滑动窗口内的k个数字.滑动窗口每次只向右移动一位. 返回滑动窗口中的最大值. 示例: 输入: nums = ...

  6. Linux内核文档:如何写符合 kernel-doc 规范的注释

    简介 Linux内核使用 Sphinx 实现把 Documentation 目录下的 reStructuredText 文件转换为非常漂亮的文档.文档既可以通过 make htmldocs 转换成 H ...

  7. win10安装ubuntu子系统和图形界面

    子系统可以很方便的调用windows的文件(在/mnt里就有各个盘),也可以在windows里用VScode编辑linux的文件.还是很方便的.也可以切出去用QQ微信. 安装子系统参考教程:https ...

  8. 数据库事务ACID详解(转载)

    转载自:http://blog.csdn.net/shuaihj/article/details/14163713 谈谈数据库的ACID 一.事务 定义:所谓事务,它是一个操作序列,这些操作要么都执行 ...

  9. 集群搭建_02_集群多机版安装 HDFS HA+Federation-YARN

    1.配置hosts 至少四个节点(机器) 每个节点的hosts文件都要配置这些 10.10.64.226 SY-0217 10.10.64.234 SY-0225 10.10.64.235 SY-02 ...

  10. 利用JDBC工具类添加和查询数据-Java(新手)

    JDBC工具类: 1 package cn.lxr.jdbclx; 2 3 import java.sql.*; 4 5 public class JDBCUtils { 6 private stat ...