import java.util.*; public class Main { static int opts; static int[] arr = new int[2]; static int num; public static void main(String[] args){ char A = 'A'; char B = 'B'; char C = 'C'; int n = new Scanner(System.in).nextInt(); num = n; //一般迭代实现,会超时。 /*hannuoTower03(A,B,C,n); arr[0] = opts; opts = 0; hannuoTower02(A,B,C,n); arr[1] = opts;*/ //使用动态规划解决 //一共有两类子问题 //一是移动两步,设为F(n),F(1)=2 //二是移动一步,设为G(n),G(1)=1 //第一个问题:将所有盘子移动到B,就是G(n) //那么这个问题可以拆解为将n-1个盘子移动两步,将第n个盘子移动1步,再将n-1个盘子移动两步 //即G(n)=F(n-1)+1+F(n-1) //第二个问题,将所有盘子移动到C,就是F(n) //那么这个问题可以拆解为将n-1个盘子移动到C,第n个盘子移动到B,n-1个盘子移动到A,第n个盘子移动到C,n-1个盘子移动到C //即F(n)=F(n-1)+1+G(n-1)+1+F(n-1) long preF = 2l; long preG = 1l; long F = 2l; long G = 1l; for(int i = 2; i <= n; i++){ F = (preF*2 + preG + 2)%1000000007; G = (preF*2 + 1)%1000000007; preF = F; preG = G; } System.out.println(G + " " + F); } public static char next(char c){ if(c=='C'){ return 'A'; }else{ return (char)(c+1); } } public static void hannuoTower01(char A, char B, char C, int n){ if(n == 1){ opts = (opts+2)%1000000007; }else{ //n-1个盘是二级跳, hannuoTower01(A,B,C,n-1); opts++;//最大盘A->B,其余盘在C hannuoTower01(C,A,B,n-1); } } public static void hannuoTower02(char A, char B, char C, int n){ if(n == 1){ opts = (opts+2)%1000000007; }else{ //n-1个盘是二级跳 hannuoTower02(A,B,C,n-1);//n-1:A-B,B-C opts = (opts+1)%1000000007;//n:A-B hannuoTower03(C,A,B,n-1);//n-1:C-A opts = (opts+1)%1000000007;//n:B-C hannuoTower02(A,B,C,n-1);//n-1:A-B,B-C } } public static void hannuoTower03(char A, char B, char C,int n){ if(n == 1){ //如果只移动一个盘,就移动一下 opts = (opts+1)%1000000007; }else{ //从A移到B //如果是多个盘,就是上面的盘先移动两步到C, //底下的盘移动一步到B,上面的盘移动两步到B hannuoTower01(A,B,C,n-1); opts = (opts+1)%1000000007; hannuoTower01(C,A,B,n-1); } } }