Tower iiitime limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 9235 accepted submission (s): 4125
Problem description about the end of the 19th century, an intellectual toy was sold in a store in ozhou with three poles on a copper plate, on the leftmost bar, the Tower consists of 64 disks in ascending order. The purpose is to move all the disks on the leftmost bar to the right bar, with the condition that only one disk can be moved at a time and the tray cannot be placed on a small disk.
Now we can change the gameplay. We cannot directly move from the leftmost (rightmost) side to the rightmost (leftmost) side (each move must be moved to or from the middle ), you cannot place the dashboard on the lower disk.
Daisy has already done the original tower problem and Tower II, but when she encountered this problem, she thought for a long time and couldn't solve it. Please help her now. Now there are n discs. How many times does she move these discs from the leftmost to the rightmost?
Input contains multiple groups of data. Each input has an N value (1 <= n = 35 ).
For each group of data, output moves the smallest number of times.
Sample Input
1312
Sample output
226531440
Assume that step f [N] is required to move the n-layer tower from A to C by B. The specific moving process can be seen as follows: It takes step f [n-1] To Move layer N from A to C through B, and then move layer N from A to B. One step is required, next, we need to move the n-1 layer from C to A by B. Step f [n-1] is required. Then we need to move the n-th layer from B to C. One step is required, next, we need to move the n-1 layer from A to C through B. Step f [n-1] is required, in total 3 * f [n-1] + 2, where F [1] = 2;
#include <stdio.h>__int64 dp[36] = {0, 2};int main(){ int n; for(n = 2; n < 36; ++n) dp[n] = dp[n-1] * 3 + 2; while(scanf("%d", &n) == 1) printf("%I64d\n", dp[n]); return 0;}