Professional Documents
Culture Documents
(/)
Problems (/problems) / classical (/problems/classical) / Tower of Babylon
Input
The number of types of blocks n is located in the rst line of each test case. On the
subsequent n lines the height yi, the width xi and the depth zi of each type of blocks are
given. There are never more than 30 di erent types available.
There are many test cases, which come one by one. Input terminates with n = 0.
Edited: You can assume that max(xi, yi, zi) <= 2500.
Output
For each test case your program should output one line with the height of the highest
possible tower.
Example
Sample input:
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
1
1 1 1
0
Sample output:
342
1
hide comments
http://www.spoj.com/problems/BABTWR/ 1/2
8/7/2017 SPOJ.com - Problem BABTWR
cake_is_a_lie (/users/cake_is_a_lie): 2017-02-28 15:18:02
This can be solved in O(N log N), but it's a bit tricky. There is a pretty obvious
O(N^2) solution and even more obvious O(N^3) that should still not TLE I think.
yingduchman_ "As it's not an ad-hoc, you are unlikely to invent or discover the
solution" - what a horribly self-limiting way of thinking. I discovered the O(N^2)
solution without reading either of your suggestions and I think it's simple to come
up with.
I was also well on the way to getting the O(N log N) before reading about the N log
N LIS - i.e. I gured BST or some other query structure could be used to improve
the O(N^2) and frankly, reading about LIS didn't help that much in guring out
how.
Leave a Comment
Publish
Notes:
1. Don't post any source code here.
2. Please be careful, leave short comments only. Don't spam here.
3. For more discussion (hints, ideas, solutions) please visit our forum (/forum).
4. Authors of the problems are allowed to delete the post and use html code here (e.g. to
provide some useful links).
Micha Czuczman
Added by:
(/users/ahven)
Date: 2004-07-06
Time limit: 3s
Source limit: 50000B
Memory limit: 1536MB
Cluster: Cube (Intel G860) (/clusters/)
http://www.spoj.com/problems/BABTWR/ 2/2