博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 1069 Monkey and Banana
阅读量:4914 次
发布时间:2019-06-11

本文共 4408 字,大约阅读时间需要 14 分钟。

 

Monkey and Banana

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 15974    Accepted Submission(s): 8477

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
 
 
题解:
该题的意思是 给你n个类型的长方体,能将这些长方体堆多高。限制条件是,堆长方体时上面那个长方体必须小于
下面的长方体,即上面长方体长和宽都必须小于下面长方体的长和宽,问最高能堆多少米。
这道题个人感觉跟另外一道DP—嵌套矩形  很相似,如果做过嵌套矩形那道题,则该题稍作转化就能出来结果。
嵌套矩形请参考:http://www.cnblogs.com/creativepower/p/7324575.html
该题类型为DAG问题(有向无环图)。
矩形的放置有6种情况,(长宽)(长高)(宽高)(宽长)(高长)(高宽)
判断该长方体能不能放置在另一个长方体上的条件是长和宽都必须小于另一个长方体的长和宽
即(s[i].x > s[j].x && s[i].y > s[j].y)
如果存在这种情况,则就要对该i的值进行更新
1 #include 
2 #include
3 4 using namespace std; 5 typedef long long LL; 6 struct node { 7 int x, y, z;//x,y表示长方体的长 宽, z表示高 8 }s[200]; 9 bool cmp(node a, node b) { //根据node中的x从小到大排序,如果x一样,则根据y从小到大排序10 if(a.x == b.x) return a.y < b.y ;11 return a.x < b.x;12 }13 14 void init(int *dp, int n) { //初始化dp数组,存入每个对应长方体的高度15 for(int i = 0 ; i < n; i++){16 dp[i] = s[i].z;17 }18 }19 20 int main()21 {22 int dp[200];23 int n, a[6];24 int E, ans , k = 1;25 while(cin >> n && n) {26 ans = 0;27 E = 0;//总共有多少种情况28 while(n--){
//长方体可以分为6种情况进行储存29 cin >> a[0] >> a[1] >> a[2];30 s[E].x = a[0], s[E].y = a[1], s[E++].z = a[2];31 s[E].x = a[0], s[E].y = a[2], s[E++].z = a[1];32 s[E].x = a[1], s[E].y = a[2], s[E++].z = a[0];33 s[E].x = a[1], s[E].y = a[0], s[E++].z = a[2];34 s[E].x = a[2], s[E].y = a[1], s[E++].z = a[0];35 s[E].x = a[2], s[E].y = a[0], s[E++].z = a[1];36 }37 sort(s, s + E, cmp);//将储存的边进行由小到大进行排序38 init(dp, E);39 for(int i = 1; i < E; i++) {
//进行判断的情况40 for(int j = 0; j < i ; j++) {41 if(s[i].x > s[j].x && s[i].y > s[j].y){42 if(dp[i] < dp[j] + s[i].z)43 dp[i] = dp[j] + s[i].z;44 }45 }46 }47 for(int i = 0 ; i < E; i++) {
//找出最高的情况48 ans = ans < dp[i] ? dp[i] : ans;49 }50 cout << "Case " <
<<": maximum height = ";51 cout << ans << endl;52 }53 return 0;54 }

 

 

转载于:https://www.cnblogs.com/creativepower/p/7324424.html

你可能感兴趣的文章
JavaScript备忘录-闭包
查看>>
词频统计报告
查看>>
Java NIO系列教程(十一) Pipe
查看>>
串口屏的特点和开发步骤 + 最好的串口屏产品推荐 .....!
查看>>
蓝桥校内选拔赛B题(不一定正确)
查看>>
数据验证
查看>>
JAVAWeb---HttpServletResponse中的方法
查看>>
一个不错的界面原型制作工具(Balsamiq Mockups)
查看>>
通过eclipse的egit插件提交提示Auth fail
查看>>
对象序列化
查看>>
UVA 208 Firetruck (DFS+剪枝)
查看>>
windows设置电脑的固定IP
查看>>
Python
查看>>
犀牛Phinoceros 如何切换中文语言
查看>>
Win7如何解决精简版的迅雷7无法运行
查看>>
C#.NET常见问题(FAQ)-如何判断某个字符是否为汉字
查看>>
直接用postman测试api ,服务器端没提供跨域也可以访问。
查看>>
数据的类型以及内置方法
查看>>
继承之super关键字的使用
查看>>
XML - 报表数据的新大陆
查看>>