欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

HDOJ 1069 Monkey and Banana

发布时间:2025/7/14 编程问答 36 豆豆
生活随笔 收集整理的这篇文章主要介绍了 HDOJ 1069 Monkey and Banana 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1:每一组X,Y,Z对应3个立方体
2:按面积从小到大DP

Monkey and Banana

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5356    Accepted Submission(s): 2744


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

 

Source University of Ulm Local Contest 1996

 

Recommend JGShining 1 #include <iostream> 2 #include <algorithm> 3 #include <cstring> 4 5 using namespace std; 6 7 struct cube 8 { 9 int l,w,h; 10 int sum; 11 }cc[111]; 12 13 bool ifso(cube a,cube b) 14 { 15 return (a.l<b.l&&a.w<b.w)||(a.w<b.l&&a.l<b.w); 16 } 17 18 bool cmp(cube a,cube b) 19 { 20 return a.l*a.w>b.l*b.w; 21 } 22 23 int main() 24 { 25 int n; 26 int cnt=1; 27 while(cin>>n&&n) 28 { 29 memset(cc,0,sizeof(cc)); 30 for(int i=0;i<3*n;i++) 31 { 32 int L,W,H; 33 cin>>L>>W>>H; 34 cc[i].l=L;cc[i].w=W;cc[i].h=H;cc[i].sum=0;i++; 35 cc[i].l=W;cc[i].w=H;cc[i].h=L;cc[i].sum=0;i++; 36 cc[i].l=H;cc[i].w=L;cc[i].h=W;cc[i].sum=0; 37 } 38 39 sort(cc,cc+3*n,cmp); 40 41 for(int i=0;i<3*n;i++) 42 { 43 int temx=0; 44 for(int j=0;j<i;j++) 45 { 46 if(cc[j].sum>temx&&ifso(cc[i],cc[j])) 47 temx=cc[j].sum; 48 } 49 cc[i].sum=temx+cc[i].h; 50 } 51 52 int ans=-1; 53 for(int i=0;i<3*n;i++) 54 { 55 ans=max(ans,cc[i].sum); 56 } 57 58 cout<<"Case "<<cnt++<<": maximum height = "<<ans<<endl; 59 } 60 61 return 0; 62 }

 

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/24/3097742.html

总结

以上是生活随笔为你收集整理的HDOJ 1069 Monkey and Banana的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。