• 滴答滴答---题目链接

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<cstring>
#include<algorithm>
using namespace std;
#define ll long long int
#define INF 0x3f3f3f3f
#define Irish_Moonshine main
const int maxn = 205;
int dp[maxn];
struct node {int x, y, z;bool operator <(const node &t)const//对于底部长进行一波排序{return x > t.x;}
}blocks[maxn];
int cnt;
void add(int x, int y, int z)
{blocks[cnt].x = x;blocks[cnt].y = y;blocks[cnt].z = z;cnt++;
}
int Irish_Moonshine()
{int n, cs = 0;while (~scanf("%d", &n) && n){cnt = 0;int a, b, c;int ans = 0;for (int i = 1; i <= n; i++){scanf("%d%d%d", &a, &b, &c);add(a, b, c);add(a, c, b);add(b, a, c);add(b, c, a);add(c, a, b);add(c, b, a);}sort(blocks, blocks + cnt);memset(dp, 0, sizeof(dp));for (int i = 0; i < cnt; i++){dp[i] = blocks[i].z;//lowestfor (int j = 0; j < i; j++)//将高度最高的放置在i下面{if (blocks[j].x > blocks[i].x&&blocks[j].y > blocks[i].y)dp[i] = max(dp[i], dp[j] + blocks[i].z);//从j的位置上再放置一个i~~~}ans = max(dp[i], ans);}printf("Case %d: maximum height = %d\n", ++cs, ans);}return 0;
}

基础dp C Monkey and Banana (类最长上升子序列)相关推荐

  1. 【HDU - 1069】Monkey and Banana (最长下降子序列 + 贪心,最长上升子序列类问题)

    题干: A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a ...

  2. hdu1243 dp (类最长公共子序列)

    题意:射击演习中,已知敌人出现的种类顺序,以及自己的子弹种类顺序,当同种类的子弹打到同种类的敌人时会得到相应分数,问最多能得多少分. 这题的题意很好理解,而且模型也很常见,是带权值的类最长公共子序列问 ...

  3. [kuangbin带你飞]专题十二 基础DP1 C - Monkey and Banana HDU - 1069

    C - Monkey and Banana HDU - 1069 题目链接:https://vjudge.net/contest/68966#problem/C 题目: A group of rese ...

  4. 【HDU - 1257】最少拦截系统 (标解dp,贪心可过,最长上升子序列类问题)

    题干: 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来 ...

  5. DP方法(动态规划) 寻找最长公共子序列 LCS问题(c++)

    Q:有两个序列x,y.其中x={x1,x2-xm},y={y1,y2-yn}.寻找x与y的最长公共子序列. 注:子序列和子串有区别,字串是连续的,而子序列可间断. 呃(⊙﹏⊙),后面的暂时没时间写了, ...

  6. 【HDU 1069】Monkey and Banana(dp+sort结构体排序)

    点击打开题目 Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  7. HDU 1069 Monkey and Banana(简单图解,经典DP,最大上升子序列变形)

    题目链接 今天做的第二题,感觉比较经典,详细记录一下吧! Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  8. kuangbin专题十二 基础DP

    kuangbin专题十二 基础DP A - HDU1024 Max Sum Plus Plus B - HDU1029 Ignatius and the Princess IV C - HDU1069 ...

  9. HDOJ 1069 Monkey and Banana

    1:每一组X,Y,Z对应3个立方体 2:按面积从小到大DP Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

最新文章

  1. cookie用法之一,最简单cookie操作
  2. 解决win8.1企业版安装WP8 SDK出现“根据当前系统时钟或签名文件中的时间戳验证时要求的证书不在有效期内”的问题
  3. 排序算法系列:插入排序算法
  4. 自动化测试在CI CD管道中的作用
  5. MySQL 创建索引
  6. Bootstrap3 表单帮助文本
  7. Spring的AOP特性
  8. ATN项目(智能矩阵Atmatrix)是否能做到人工智能界的桥梁,从而改变世界?
  9. 谈谈百度竞价的一些思路
  10. 微信小程序进度条样式_微信小程序——自定义圆形进度条
  11. CS5801HDMI转eDP/DP转换芯片资料|CS5801规格书
  12. 遥感图像存储格式BSQ/BIL/BIP
  13. ios11.2计算机更新,iOS11.2.2正式版怎么样、更新了什么?iOS11.2.2降频吗?
  14. Citrix XenDesktop 简介
  15. 贾扬清从阿里毕业了!
  16. @RequiredArgsConstructor注解使用
  17. Android Framework学习(八)之Handler消息机制(Native层)解析
  18. 协程(二):协程的应用
  19. 使用python编写一个简易的打折程序
  20. 游戏服务器为空请检查列表,游戏服务器为空请检查列表文件

热门文章

  1. php添加附件,通过PHPMailer添加附件
  2. 在Windows7下,做开发时怎么创建.babelrc文件
  3. 解决:小米手机电源键坏了怎么开机
  4. tinymce采用cdn.jsdelivr.net cdn经常挂怎么办?
  5. Opencv中的GrabCut图像分割
  6. React_04 菜谱项目
  7. 2022-2028年中国铁合金行业竞争格局分析及投资发展研究报告
  8. php设计模式-组合模式的运用
  9. Android自定义View——仿1号店垂直滚动广告条实现
  10. 智云物业4.20+前端,物业小程序源码+前端+公众号