Tower of Hanoi
Practice
4.3 (66 votes)
Algorithms
Approved
Dynamic programming
Easy
Open
Problem
85% Success 7187 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Bob and Alice like to play the game tower of Hanoi. One day Alice challenges Bob to build the tallest tower from a set of disks of different height and radius. The tower of Hanoi can be built by stacking disks on top of each other. In order to put disk A on top of disk B, the radius and height of A must be strictly smaller than those of B. Help Bob to win the challenge.

Input:
First line of input contains number of test cases T.
First line of each test case contains value of N, the number of disks. The next N lines contains two positive integer number Ri and Hi corresponding to the radius and height of ith Disk respectively.

Output:
For each test case print the maximum height of the tower possible.

Constraints:
1<=T<=10
1<=N<=200
1<=Ri, Hi<=10^9

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
32 votes
Tags:
EasyMathOpen
Points:20
42 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingEasyOpen
Points:20
89 votes
Tags:
ApprovedBasic ProgrammingDynamic ProgrammingEasyImplementationOpen