7430. 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.)
Constraints:
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
CODE
t=input()
for i in range(t):
a=input()
print (3**a-1)
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.)
Constraints:
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
CODE
t=input()
for i in range(t):
a=input()
print (3**a-1)
No comments:
Post a Comment