RANJAN02 - Tower Of Hanoi - Revisited
Given 3 three pegs: leftmost peg A, middle peg B and rightmost peg C.Find the shortest sequence of moves that transfers a tower of n disks from the left peg A to the right peg C, if direct moves between A and C are disallowed. (Each move must be to or from the middle peg B.)
1. Initially the left peg A in stacked by n disks in the order of decreasing size.
2. Only one move cand be done at a time and never moving a larger one onto a smaller.
3. Number of moves will always be less than 2^64.
4. 1 <= n <= 35
Input begins with a integer t, followed by t lines. Each line has the no. of pegs n.
For each test case, output the minimum no. of move required to transfer the n disks from peg A to peg C.
AC in one go :)
easy dp AC with little precomputation and O(1)
Easy....AC at once
little precomputation with dp and then o(1) retriveal.
python rocks!! 1 line :-)
check the constraints carefully!!!!!
5 lines in python is an overkill. 1 is enough, 2 is plenty for readability.
5 lines in python !
It's seems to be a subcase of problem VIENTIAN.
@~ - Constraint 3 may help you.