# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2006-08-09 08:57 by
很羨慕你的說,大學(xué)里能夠這么有耐心的研究算法。我一直在考慮我能夠在計算機領(lǐng)域內(nèi)發(fā)展到什么層次?恐怕這些我不感興趣的算法以后會成為我很大的阻礙阿 !
# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2006-08-09 11:03 by
是自從接觸ACM以來才知道自己原來水平有多菜~~(呵呵) 后來才知道原來自己與別人的差距有多大啊~~ 從最簡單的算法開始認認真真學(xué) 爭取早日走出菜鳥的圈圈
# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2006-08-09 18:14 by
# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2006-08-09 19:11 by
非常感謝SoRoMan對這道題的關(guān)注,甚至還為此寫出了完整的程序。
程序?qū)懙暮芷粒浅8兄x。
由于本人的疏忽 題目描述地不是很清楚,所以特此也把整個原題貼出來(由于已經(jīng)寫了簡述,故不再翻譯原題(呵呵,實際上是沒那英文水準~~-_-))
The Tower of Babylon
Time Limit:1000MS Memory Limit:65536K
Total Submit:230 Accepted:147
Description
Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell you the whole story:
The babylonians had 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 wanted to construct the tallest tower possible by stacking blocks. The problem was 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. 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 babylonians can build with a given set of blocks.
Input
The input 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
Source
Ulm Local 1996
# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2007-07-29 21:23 by
非常感謝師兄的提示,我DP一貫很差,今個有過了一個。。。受益匪淺!TH
# re: 今天我做的一道經(jīng)典動歸題The Tower of Babylon 回復(fù) 更多評論
2009-04-30 14:32 by
lz的沒看太明白呢,不過我用深度優(yōu)先搜索的方法做出來了哦
算法分析如下:
1) 將n個石塊存入blocks[3n]中(如lz一樣把每一塊分成三塊,但不用求面積,也不用排序)
2) 構(gòu)建blocks的有向鄰接表adj。(eg blocks[i]--> block[j] 的條件是 i的底部長寬都比j的小 即,嚴格小于)
3) 深度優(yōu)先搜索整個鄰接表。并用一個數(shù)組height[n]記錄以每一個節(jié)點為最底層塊的時候的最大高度
4) 遍歷height[n],值最大的那個就是所求的最大高度了。