On the Day of the Flag of Russia a shop-owner decided to decorate the show-window of his shop with textile stripes of white, blue and red colors. He wants to satisfy the following conditions:
- Stripes of the same color cannot be placed next to each other.
- A blue stripe must always be placed between a white and a red or between a red and a white one.
Determine the number of the ways to fulfill his wish.
Example. For N = 3 result is following:
Input
N, the number of the stripes, 1 ≤ N ≤ 45.
Output
M, the number of the ways to decorate the shop-window.
Sample
Problem Source: 2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002
1 int main2() {
2 int N;long long dp[46][3]={0};
3 dp[1][0]=dp[1][2]=1;
4 scanf("%d", &N);
5 for(int i=2; i<=N; i++)
6 dp[i][0]=dp[i-2][2]+dp[i-1][2],
7 dp[i][1]=dp[i-1][0]+dp[i-1][2],
8 dp[i][2]=dp[i-2][0]+dp[i-1][0];
9 printf("%lld\n",dp[N][0]+dp[N][2]);
10 return 0;
11 }
1 int main() {
2 int N;long long dp[46]={0,2,2};
3 scanf("%d", &N);
4 for(int i=3; i<=N; i++)
5 dp[i]=dp[i-1]+dp[i-2];
6 printf("%lld\n",dp[N]);
7 return 0;
8 }