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. 实例:ABAP权限对象设计与权限检查的实现(详细)

    学习总结,分享给大家,,,(有图有真像) 我在ECC里创建了一张表,随意插入了5条数据 创建权限对象,使分配这个权限的用户只能操作部门编号(edept)为 ‘10’ 的数据. 1. SU20,创建权限 ...

  2. Android上实现仿IOS弹性ScrollView

    [转]http://www.tuicool.com/articles/ummIJb

  3. 理解C++ 宏

    1.什么是宏,它解决什么问题? 宏的本质是文本替换,考虑下面的需求,程序中多次使用圆周率Pi,在每个地方都使用3.1415,显然很愚蠢.有没有好的办法呢?使用宏,如下: #define Pi 3.14 ...

  4. ThinkPHP Volist标签

    Volist标签主要用于在模板中循环输出数据集或者多维数组. volist标签(循环输出数据) 闭合 非闭合标签 属性 name(必须):要输出的数据模板变量 id(必须):循环变量 offset(可 ...

  5. android学习日记03--常用控件checkbox/radiobutton

    常用控件3.checkbox 复选框,确定是否勾选,点击一下勾选,点击第二下取消,当有一系列备选项时适合用checkbox控件,方便用户提交数据. 贴上例子Activity的java代码 packag ...

  6. javascript 递归之阶乘

    阶乘,即5! = 5*4*3*2*1, 先看传统的做法,利用while循环实现: function factorial(num){ var result = num; if(num<0){ re ...

  7. 大型高性能ASP.NET系统架构设计

    大型动态应用系统平台主要是针对于大流量.高并发网站建立的底层系统架构.大型网站的运行需要一个可靠.安全.可扩展.易维护的应用系统平台做为支撑,以保证网站应用的平稳运行. 大型动态应用系统又可分为几个子 ...

  8. Input

    Input Basic Input Old Input Files Please note that both Input and Request do NOT sanitize your data, ...

  9. c/c++中动态内存分配处理字符串的细节问题

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h&g ...

  10. iOS之NSUserDefaults的用法

    NSUserDefaults适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名.密码之类的,个人觉得使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefa ...