1225. Flags
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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
input | output |
---|---|
3 | 4 |
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 50
long long dp[maxn][2];//w 0 r 1//easy
int n;
void read()
{
scanf("%d",&n);
}
void DP()
{
dp[1][0]=1;dp[2][0]=1;
dp[1][1]=1;dp[2][1]=1;
for(int i=3;i<=n;i++)
{
dp[i][0]=dp[i-1][1]+dp[i-2][1];
dp[i][1]=dp[i-1][0]+dp[i-2][0];
}
printf("%lld\n",dp[n][0]+dp[n][1]);
}
int main()
{
read();
DP();
return 0;
}