Space Elevator
Time Limit:
1000MS |
|
Memory Limit:
65536K |
Total Submissions:
2690 |
|
Accepted:
1101 |
Description
The
cows are going to space! They plan to achieve orbit by building a sort
of space elevator: a giant tower of blocks. They have K (1 <= K
<= 400) different types of blocks with which to build the tower.
Each block of type i has height h_i (1 <= h_i <= 100) and is
available in quantity c_i (1 <= c_i <= 10). Due to possible
damage caused by cosmic rays, no part of a block of type i can exceed a
maximum altitude a_i (1 <= a_i <= 40000).
Help the cows build the tallest space elevator possible by stacking blocks on top of each other according to the rules.
Input
* Line 1: A single integer, K
* Lines 2..K+1: Each line contains three space-separated integers: h_i, a_i, and c_i. Line i+1 describes block type i.
Output
* Line 1: A single integer H, the maximum height of a tower that can be built
Sample Input
3
7 40 3
5 23 8
2 52 6
Sample Output
48
Hint
OUTPUT DETAILS:
From the bottom: 3 blocks of type 2, below 3 of type 1, below 6 of
type 3. Stacking 4 blocks of type 2 and 3 of type 1 is not legal, since
the top of the last type 1 block would exceed height 40.
Source
題目大意:
將k種block(每種不超過c[i]),堆得儘量高,但是對某i種block,高度不能超過a[i].求最大高度
1.如果沒有高度限制,只是簡單的堆積,全部用上最好。
2.有高度限制,就像揹包的容量限制,只不過對每種的限制不一樣而已,既然這樣,我們將限制高度從小到大先排列一下,如果保證限制高度小的在下面,那麼一定可以構造出最優解。
3.轉換成了限制數量的物品加入揹包問題(xiaoz想到了限制數量的錢幣湊錢問題---得到了n^2方法,強大!)。
設exist[i][j]表示前i個是否能湊成高度爲j的block~
如果按照n^3方法(當然存在一些優化),就是枚舉已經排好序的物品,以及物品個數,枚舉可以湊到的高度,將相應能湊到的高度標記即可。
用xiaoz的方法就是:首先對高度進行枚舉,同時記錄對任意高度需要某種block的最小值,在枚舉構造過程中改變這個需要的最小值,最後求出最大的高度即可。初始化0高度需要任一種爲0。
moving:如果時限要求嚴格一點也許我的方法就過不去了,沒有想到已經用過的方法,應該反省一下。