Problem 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<stdio.h>
#include<string.h>
#include<stdlib.h> struct stu
{
int x,y,z,h;
}s[]; int cmp1(const void *a,const void *b)
{
return *(int *)b-*(int *)a;
} int cmp2(const void *a,const void *b)
{
struct stu *c,*d;
c=(struct stu*)a;
d=(struct stu*)b;
return d->x*d->y-c->x*c->y;
} int main()
{
int n,a[],i,m,maxn,j,q=;
while(scanf("%d",&n),n)
{
memset(s,,sizeof(s));
i=;
while(n--)
{
scanf("%d%d%d",&a[],&a[],&a[]);
qsort(a,,sizeof(a[]),cmp1);
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
s[i].x=a[];
s[i].y=a[];
s[i++].z=a[];
}
m=i;
qsort(s,m,sizeof(s[]),cmp2);
s[].h=s[].z;
for(i=;i<m;i++)
{
maxn=;
for(j=;j<i;j++)
{
if(s[j].h>maxn&&s[j].x>s[i].x&&s[j].y>s[i].y)
maxn=s[j].h;
}
s[i].h=s[i].z+maxn;
}
maxn=;
for(i=;i<m;i++)
{
if(s[i].h>maxn)
maxn=s[i].h;
}
printf("Case %d: maximum height = %d\n",q++,maxn);
}
return ;
}

因为有很多个积木  所以要存三次。

动态规划:Monkey and Banana的更多相关文章

  1. HDU——Monkey and Banana 动态规划

                                                                       Monkey and Banana Time Limit:2000 ...

  2. Monkey and Banana 题解(动态规划)

    Monkey and Banana 简单的动态规划 1.注: 本人第一篇博客,有啥不足还请多多包涵,有好的建议请指出.你以为有人读你博客,还给你提意见. 2.原题 Background: A grou ...

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

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

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

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

  5. HDU 1069 Monkey and Banana (动态规划、上升子序列最大和)

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

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

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

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

  8. HDU 1069 Monkey and Banana dp 题解

    HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...

  9. hdu 1069 Monkey and Banana

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

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

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

随机推荐

  1. 【HEVC简介】CTU、CU、PU、TU结构

     参考文献:见<High Efficiency Video Coding (HEVC)>Block Structures and Parallelism Features in HEVC章 ...

  2. Redis学习笔记(六)有序集合进阶

    1.基础操作 ZCARD(获取成员数量) ZINCRBY key_name num member(将member的分数加num) ZCOUNT key_name min max(获取分数在min与ma ...

  3. css广告弹窗满屏跑

    window.onload=function(){ //广告滚动 var oneInner = $('#divid')[0]; //定时器 var a1a = setInterval(moves,10 ...

  4. Big Data Mindmap

  5. leetcode_935. Knight Dialer_动态规划_矩阵快速幂

    https://leetcode.com/problems/knight-dialer/ 在如下图的拨号键盘上,初始在键盘中任意位置,按照国际象棋中骑士(中国象棋中马)的走法走N-1步,能拨出多少种不 ...

  6. Java 游戏报错 看不懂求教

    Java 飞机小游戏 报错 看不懂求救 at java.awt.Component.dispatchEvent(Unknown Source)at java.awt.EventQueue.dispat ...

  7. 在CNN网络中roi从原图映射到feature map中的计算方法

    在使用fast rcnn以及faster rcnn做检测任务的时候,涉及到从图像的roi区域到feature map中roi的映射,然后再进行roi_pooling之类的操作.比如图像的大小是(600 ...

  8. 【搜索】P1219 八皇后

    题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序列2 4 6 1 3 ...

  9. WebGL 绘制Line的bug(三)

    之前铺垫了许多,今天可以来分享点纯干货了. 上一篇已经讲述了通过面模拟线条时候,每一个顶点的顶点数据包括:端点坐标.偏移量.前一个端点坐标.后一个端点坐标,当然如果我们通过索引的方式来绘制的话,还包括 ...

  10. C指针类型转换问题

    先看下面的代码: #include<stdio.h> int main () { int a; char *x; x = (char *) &a; a = 512; x[0] = ...