Title Description
Description
Given a, B, c three long enough of the fine column, on the A column is placed 2n holes in the middle of the disk, a total of n different dimensions, each size has two identical discs, note that the two discs are not differentiated (for n=3 case). These discs are now moved to the C-pillar and can be staged on the B-pillar during movement. Requirements:
(1) Only one disc can be moved at a time;
(2) A, B, c three thin column on the disk should be kept small under the large order;
Task: Set an to 2N discs to complete the minimum number of moves required for the above tasks, and for input n, output An.
Enter a description
Input Description
is a positive integer n, which indicates that there are 2n discs placed on a column.
Output description
Output Description
A single row that contains a positive integer that is the minimum number of moves required to complete the above task.
Sample input
Sample Input
2
Sample output
Sample Output
6
Data range and Tips
Data Size & Hint
For 50% of data, 1<=n<=25
For 100% of data, 1<=n<=200
Try to establish a recursive relationship between an and an-1.
Code:
var a:array[1..200]of Longint; B:array[1..10000]of integer; N,i,j,m:longint;begin readln (n); a[1]:=2; If N<26 then the begin for i:=2 and n do a[i]:=a[i-1]*2+2; Writeln (A[n]); End Else begin b[1]:=2;b[2]:=6;b[3]:=8;b[4]:=8;b[5]:=0;b[6]:=1;b[7]:=7;b[8]:=6; m:=8; For i:=26 to n does begin for j:=1 to M do b[j]:=b[j]*2; b[1]:=b[1]+2; For J:=1 to M do begin B[j+1]:=b[j]div 10+b[j+1]; B[J]:=B[J] MoD ten; End; Inc (M); End; While b[m]=0 do m:=m-1; For i:=m Downto 1 do write (B[i]); End;end
The fourth question of "NOIP2007" · Hanoi Twin Towers problem