HDU 1207 Tower II
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1207
The typical tower issue of Problem description is often used as a recursive classic example. Some people may not know the story of the tower. A story from the legend of India tells the story that, when God created the world, he made three diamond pillars with 64 gold disks stacked from bottom to top in order of size. God ordered the Brahman to re-place the disc from below in order of size on another pillar. It is also stipulated that the disc cannot be enlarged on a small disc, and only one disc can be moved between the three pillars. It was predicted that the universe would flash into destruction at the completion of the event. Some people believe that the Brahman still keeps moving the disc for a moment. Well, of course, this legend is not credible, and now the tower is more of a toy. Gardon received a birthday present from the toy tower.
Gardon is a troublesome person (well, a lazy person). Obviously, it is difficult to move 64 discs one by one until all the plates reach the third pillar, so gardon decided to make a small disadvantage, and he found another identical pillar, through which he quickly moved all the dishes to the third pillar. The following question is: How many times does gardon need to move each of the N plates in a game to the third pillar? Obviously, when there is no fourth pillar, the solution to the problem is 2 ^ N-1, but now with the help of this pillar, what is it?
Input contains multiple groups of data. Each Data row contains N (1 <= n <= 64) Number of plates ).
Output outputs a number for each group of data, which is the minimum movement required to reach the target.
Sample input1 3 12
Sample output1 5 81
Rule:
A [1] = 1;
A [2] = A [1] + 2; A [3] = A [2] + 2; (2 plus 2 ^ 1)
A [4] = A [3] + 4; A [5] = A [4] + 4; A [6] = A [5] + 4; (3 plus 2 ^ 2 );
................................................ (4 plus 2 ^ 3 );
# Include <iostream>
# Include <cmath>
Using namespace STD;
Int main ()
{
Int A [66];
A [1] = 1;
Int I, N, P = 2, D = 0;
For (I = 2; I <= 64; I ++)
{
If (P = D)
{
P ++ ;;
D = 0;
}
A [I] = A [I-1] + POW (2, P-1 );
D ++;
}
While (~ Scanf ("% d", & n ))
{
Printf ("% d \ n", a [n]);
}
Return 0;
}