题目传送门
1 /*
2 1 r; 2 b; 3 w
3 2不能在最前面,所以dp[1] = 2; dp[2] = 2: 13 or 31
4
5 dp[i] = dp[i-1] + dp[i-2];
6 只加1或3时,总数dp[i-1]; 只加12或32时,总数dp[i-2];
7 详细解释:http://www.cnblogs.com/vongang/archive/2011/09/30/2196847.html
8 */
9 #include <cstdio>
10 #include <iostream>
11 #include <algorithm>
12 #include <cstring>
13 using namespace std;
14
15 const int MAXN = 55;
16 const int INF = 0x3f3f3f3f;
17 long long dp[MAXN];
18
19 int main(void) //URAL 1225 Flags
20 {
21 //freopen ("A.in", "r", stdin);
22
23 int n;
24 while (scanf ("%d", &n) == 1)
25 {
26 memset (dp, 0, sizeof (dp));
27
28 dp[1] = 2; dp[2] = 2;
29 for (int i=3; i<=n; ++i)
30 {
31 dp[i] = dp[i-1] + dp[i-2];
32 }
33
34 printf ("%I64d
", dp[n]);
35 }
36
37 return 0;
38 }