Title: In the original Hanoi game based on a pillar, mobile strategy is: To move N Hanoi, first with 4 pillars of K to a pillar, and then use the remaining 3 to move the remaining n-k to the target column, and then use 4 to move the initial K to the target column.
The key question is how much to find the K of each n, the observed rule is: with the increment of K, in fact the number of moves FN (k) increment after decrement, then F1 (k), F2 (k),... The maximum value increases with the increment of K. It seems more difficult to formalize the proof. But within the scope of the topic this can be AC. The program maintains this currently makes Fi (k) the largest k, and then recursion.
Import Java.util.*;import java.math.*;p ublic class main{public static void Main (string[] args) {Scanner input=new Scanner (system.in); int u,n;final BigInteger two=new BigInteger ("2"); Biginteger[] A=new biginteger[210]; Biginteger[] D=new biginteger[10010]; BigInteger minp;a[0]=biginteger.zero;for (int i=1;i<=200;i++) {a[i]=a[i-1].multiply (both). Add (Biginteger.one);} D[0]=biginteger.zero;d[1]=biginteger.one;d[2]=new BigInteger ("3"); u=1;for (int i=3;i<=10000;i++) {Minp=d[u]. Multiply (both). Add (A[i-u]), while ((u<i-1) && (Minp.compareto (d[u+1].multiply)))) {minp=d[u+1].multiply (n). Add (A[i-u-1]); u++;} D[I]=MINP;} while (Input.hasnext ()) {n=input.nextint (); System.out.println (D[n]);}}
UVA 10254-the Priest mathematician (large number + recursive)