hdu 1069 Monkey and Banana -->dp
来源:互联网 发布:网络摄像头网址 编辑:程序博客网 时间:2024/05/17 01:31
Monkey and Banana
题意:
有 t 组数字,每组三个数,做为一类长方体的,长,宽,高,由于高可以是三个数字中的任意一个,所以每三个数字一般能代表3种不同类型的长方体
假设每种长方体有无限多个,问以垒积木的方式(上方的积木必须严格小于下方的积木),最多可以垒多高
本题可以用dp来解,先按照如果长相等宽大的放在前面,如果不等,按长由大到小排序.由于里面存在如 (9,1) (7,8)这样的对,而且不能保证这一段序列都是如题意所述,严格单调递减的,所以不能用贪心去解答.递推式:在编号为i,j的两个长方体严格单调递减的情况下,dp[i]=max(dp[j]+h,dp[i]).
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.
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.
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
110 20 3026 8 105 5 571 1 12 2 23 3 34 4 45 5 56 6 67 7 7531 41 5926 53 5897 93 2384 62 6433 83 270
Sample Output
Case 1: maximum height = 40Case 2: maximum height = 21Case 3: maximum height = 28Case 4: maximum height = 342
code:
#include<string>#include<string.h>#include<stdio.h>#include<algorithm>#include<iostream>#include<queue>#include<math.h>using namespace std;#define maxf(a,b) a>b?a:bconst int inf=0x3f3f3f3f;struct node{ int l,w,h;} b[1000];bool cmp(node a, node b){ if(a.l==b.l) return a.w>b.w; return a.l>b.l;}int main(){ int t,fff=1; while(~scanf("%d",&t)&&t) { int j=0,a[4]; for(int i=0; i<t; i++) { scanf("%d%d%d",&a[0],&a[1],&a[2]); sort(a,a+3); b[j].l=a[1],b[j].w=a[0],b[j++].h=a[2]; b[j].l=a[2],b[j].w=a[0],b[j++].h=a[1]; b[j].l=a[2],b[j].w=a[1],b[j++].h=a[0]; } sort(b,b+j,cmp); int dp[1000]; for(int i=0; i<j; i++) dp[i]=b[i].h; int max1=-1; for(int i=j-1; i>=0; i--) { for(int k=i+1; k<j; k++) { if(b[i].l>b[k].l&&b[i].w>b[k].w) dp[i]=dp[i]>dp[k]+b[i].h?dp[i]:dp[k]+b[i].h; } max1=dp[i]>max1?dp[i]:max1; } printf("Case %d: maximum height = %d\n",fff++,max1); }}
0 0
- hdu 1069 Monkey and Banana (DP)
- hdu 1069 Monkey and Banana(dp)
- HDU-1069 Monkey and Banana (DP)
- Hdu 1069 Monkey and Banana -- DP
- HDU 1069 Monkey and Banana DP LIS
- HDU 1069 Monkey and Banana(DP)
- hdu 1069 Monkey and Banana(简单dp)
- HDU 1069 Monkey and Banana(dp)
- HDU 1069 Monkey and Banana DP
- Monkey and Banana - HDU 1069 dp
- hdu 1069 Monkey and Banana (dp)
- [HDU 1069]Monkey and Banana(DP)
- 【DP|LIS】HDU-1069 Monkey and Banana
- hdu 1069 Monkey and Banana dp
- HDU 1069 Monkey and Banana (dp)
- hdu 1069 Monkey and Banana(dp)
- HDU 1069Monkey and Banana Dp问题
- hdu 1069 Monkey and Banana(dp)
- set四个集合操作&&红黑树初识
- listview访问服务器后适配数据不加载
- 几个简单的排序
- (二)基于Eclipse的STM32工程建立
- HDU5222 Exploration(拓扑排序+并查集)
- hdu 1069 Monkey and Banana -->dp
- oschina中Git中代码托管的详细步骤
- (c++)——内联函数
- javascript修改html元素的class实例,时间修改样式
- PHP的基本语法(三)
- 学习靠自觉
- Java Error和Exception
- java过滤器和监听器详解
- android Activity之间数据传递 Parcelable和Serializable接口的使用