Monkey and Banana

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 <iostream>
# include<cstdio>
# include<cstring>
# include<cstdlib>
using namespace std;
struct node
{
int x,y,z;
} s[]; int cmp(const void *a,const void *b)
{
struct node* aa = (node *)a;
struct node* bb = (node *)b;
if(aa->x != bb->x)
return aa->x - bb->x;
else if(aa->y != bb->y)
return aa->y - bb->y;
return aa->z - bb->z;
}
int dp[];
int main()
{
int n,i,j,a,b,c;
int cas = ;
while(scanf("%d",&n)&&n)
{
for(i=; i<n; i++)
{
scanf("%d%d%d",&a,&b,&c);
s[i*].x = a; s[i*].y = b; s[i*].z = c;
s[i*+].x = a; s[i*+].y = c; s[i*+].z = b;
s[i*+].x = b; s[i*+].y = a; s[i*+].z = c;
s[i*+].x = b; s[i*+].y = c; s[i*+].z = a;
s[i*+].x = c; s[i*+].y = a; s[i*+].z = b;
s[i*+].x = c; s[i*+].y = b; s[i*+].z = a;
}
qsort(s,n*,sizeof(s[]),cmp);
for(i=; i<*n; i++)
dp[i] = s[i].z;
int ans = ;
for(i=; i<n*; i++)
{
for(j=; j<i; j++)
{
if(s[i].x > s[j].x && s[i].y > s[j].y && dp[j]+s[i].z > dp[i])
dp[i] = dp[j]+s[i].z ;
}
if(dp[i]>ans)
ans = dp[i];
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
return ;
}

HDU 1069 Monkey and Banana(动态规划)的更多相关文章

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

  2. HDU 1069 Monkey and Banana dp 题解

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

  3. HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...

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

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

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

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

  6. HDU 1069 Monkey and Banana (DP)

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. hdu 1069 Monkey and Banana

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

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

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

随机推荐

  1. Oracle函数汇总

    日期函数 1. select sysdate from dual 查询当前日期 2. select months_between() from dual 查询两个日期的月份差 3. select ad ...

  2. 一步一步学android控件(之十五) —— DegitalClock & AnalogClock

    原本计划DigitalClock和AnalogClock单独各一篇来写,但是想想,两个控件的作用都一样,就和在一起写一篇了. DegitalClock和AnalogClock控件主要用于显示当前时间信 ...

  3. linux系统基础(二)

    磁盘管理(一) Linux设备认识 /dev/cdrom /dev/sr0 /dev/mouse /dev/sda /dev/hda IDE硬盘(支持4块):hd(a-d) [非IDE硬盘]SCSI硬 ...

  4. The maximum number of cell styles was exceeded. You can define up to 4000 styles

    POI操作Excel中,导出的数据不是很大时,则不会有问题,而数据很多或者比较多时, 就会报以下的错误,是由于cell styles太多create造成,故一般可以把cellstyle设置放到循环外面 ...

  5. centos 改动字符集为GB2312的方法

    这几天总是被一个问题困扰着,那就是base64的加密,在centos server上无法解密.经过重复測试才发现,原来是由于centos 系统没有GB2312库导致的. 加密端是在ASP.NET中处理 ...

  6. [Practical Git] Diagnose which commit broke something with git bisect

    Sometimes you find a bug in your project that has been around for a while without being noticed; it ...

  7. iOS开发——新特性OC篇&IOS9 系统新特性

    IOS9 系统新特性 2015年6月89号凌晨召开的WWDC 2015苹果开发者大会发布了全新的iOS 9系统,PC6小编今天给大家整理了这次iOS9的系统更新带来了哪些新的功能与升级,本次新功能一览 ...

  8. ABAP程序执行效率和优化 ABAP Performance Examples

    一.             SQL Interface1.         Select ... Where vs. Select + Check用Select … Where语句效率比Select ...

  9. Android 快速开发框架网络篇-Android-Async-Http

    一.基本用法 AsyncHttpClient client = new AsyncHttpClient(); client.get("http://www.google.com", ...

  10. html笔记 横向两列布局

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...