p2392_Space Elevator

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:如果时限要求严格一点也许我的方法就过不去了,没有想到已经用过的方法,应该反省一下。
发布了50 篇原创文章 · 获赞 1 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章