这个题目至今还没想明白,想当初高考的时候都是(n-1)(n-1)(n-1)...(n-1)(n-1+n-2),好像是递推,不过好像不一样
看解释:
递推式f(n)=f(n-1)+2*f(n-2)
思路:第n中情况由第n-1和n-2种情况决定
1、n-2格颜色跟第一种一样,n-1格随便选,就有f(n-1)种
2、n-2格颜色跟第一种不一样,这一格有2种情况,而n-1格只有一种情况,有2*f(n-2)种
1 #include<stdio.h>
2 __int64 f[51]={0,3,6,6};
3 int main()
4 {
5 int n,i;
6 for(i=4;i<51;i++)
7 f[i] = f[i-1]+f[i-2]*2;
8 while(scanf("%d",&n)==1)
9 {
10 printf("%I64d\n",f[n]);
11 }
12 return 0;
13 }