Monkey and Banana hdu(1069)
来源:互联网 发布:linux将文件夹打包 编辑:程序博客网 时间:2024/04/29 11:56
Monkey and Banana
TimeLimit: 2000/1000 MS(Java/Others)Total Submission(s):3594
Problem Description
A group of researchers are designing an experiment to test the IQof a monkey. They will hang a banana at the roof of a building, andat the mean time, provide the monkey with some blocks. If themonkey is clever enough, it shall be able to reach the banana byplacing one block on the top another to build a tower and climb upto get its favorite food.
The researchers have n types of blocks, and an unlimited supply ofblocks of each type. Each type-i block was a rectangular solid withlinear dimensions (xi, yi, zi). A block could be reoriented so thatany two of its three dimensions determined the dimensions of thebase and the other dimension was theheight.
They want to make sure that the tallest tower possible by stackingblocks can reach the roof. The problem is that, in building atower, one block could only be placed on top of another block aslong as the two base dimensions of the upper block were bothstrictly smaller than the corresponding base dimensions of thelower block because there has to be some space for the monkey tostep on. This meant, for example, that blocks oriented to haveequal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of thetallest tower the monkey can build with a given set ofblocks.
The researchers have n types of blocks, and an unlimited supply ofblocks of each type. Each type-i block was a rectangular solid withlinear dimensions (xi, yi, zi). A block could be reoriented so thatany two of its three dimensions determined the dimensions of thebase and the other dimension was theheight.
They want to make sure that the tallest tower possible by stackingblocks can reach the roof. The problem is that, in building atower, one block could only be placed on top of another block aslong as the two base dimensions of the upper block were bothstrictly smaller than the corresponding base dimensions of thelower block because there has to be some space for the monkey tostep on. This meant, for example, that blocks oriented to haveequal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of thetallest tower the monkey can build with a given set ofblocks.
Input
The input file will contain one or more test cases. The first lineof each test case contains an integer n,
representing the number of different blocks in the following dataset. The maximum value for n is 30.
Each of the next n lines contains three integers representing thevalues xi, yi and zi.
Input is terminated by a value of zero (0) for n.
representing the number of different blocks in the following dataset. The maximum value for n is 30.
Each of the next n lines contains three integers representing thevalues 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 (theyare numbered sequentially starting from 1) and the height of thetallest possible tower in the format "Case case: maximum height =height".
Sample Input
1
10 2030
2
6 810
5 55
7
1 11
2 22
3 33
4 44
5 55
6 66
7 77
5
31 4159
26 5358
97 9323
84 6264
33 8327
0
Sample Output
Case1: maximum height = 40
Case2: maximum height = 21
Case3: maximum height = 28
Case4: maximum height = 342
Source
University of Ulm Local Contest 1996
#include <stdio.h>#include<algorithm>#include<iostream>#define MAX 1000using namespace std;int max(int a,int b){ return a>b?a:b;}struct ar{ int a,b,h,s;}area[3000];int cmp(ar s,ar t){ return s.s>t.s;}int x[MAX],y[MAX],z[MAX],dp[MAX];int main(){ int n,i,j ,w = 1; while(~scanf("%d",&n)&&n){ int h=0; for(i=0;i<n;i++) scanf("%d%d%d",&x[i],&y[i],&z[i]); for(i=0;i<n;i++) for(j=0;j<3;j++){ area[h].a = x[i]; area[h].b = y[i]; area[h].h = z[i]; area[h].s = x[i]*y[i]; h++; swap(x[i],z[i]); swap(x[i],y[i]); } //for(i=0;i<h;i++) // printf("%d %d %d%d\n",area[i].a,area[i].b,area[i].h,area[i].s); sort(area,area+h,cmp); int ans=0; dp[0]=area[0].h; for(i=1;i<h;i++){ dp[i]=area[i].h; for(j=0;j<i;j++){ if(( area[i].a < area[j].a &&area[i].b < area[j].b )||( area[i].a < area[j].b&&area[i].b<area[j].a)) dp[i]=max(dp[i],dp[j]+area[i].h); } if(dp[i]>ans) ans=dp[i]; } printf("Case %d: maximum height =%d\n",w++,ans); } return 0;}
0 0
- hdu 1069 Monkey and Banana (DP)
- HDU 1069 Monkey and Banana(DP)
- Monkey and Banana hdu(1069)
- hdu 1069 Monkey and Banana(背包)
- 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)
- HDU 1069 Monkey and Banana (C)
- HDU 1069 Monkey and Banana(dp)
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- hdu 1069 Monkey and Banana
- HDU 1069 Monkey and Banana
- Common Subsequence(hdu 1159)
- 最长公共子序列
- Dijkstra算法(单源最短路径)
- hdu(Number Sequence 1711)kmp
- hdu1025(最长上升子序列)
- Monkey and Banana hdu(1069)
- 报错:Link of class 'Lcom/.../PersistentConnectionListener;' failed ...VFY: unable to resolve new-insta
- A Problem With Fibonacci Sequence
- nginx常见错误---持续更新
- Similar Word
- The Frog’s Games(hdu 4004)
- hdu1003
- poj 1067
- 由poj 1067引发的——取石子游…