1225. Flagstime limit:1.0 Second
Memory limit:64 MB
On the day of the Flag of Russia a shop-owner decided to decorate the show-window of the He shop with textile stripes of whit E, blue and red colors. He wants to satisfy the following conditions:
- Stripes of the same color cannot is placed next to all other.
- A blue stripe must always being 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
Tags:Dynamic Programming()
Test Instructions: Blue can only be between white red and cannot be placed in the same color continuously. There are several ways to askwater problem, simple DP.
#include <algorithm> #include <map> #include <cstring> #include <cmath> #include <iostream >using namespace std; #define Lson L, M, RT << 1#define Rson m + 1, R, RT << 1 | 1#define ll __int64typedef long long LL; #define PI 3.1415926ll Dp[46];int Main () { int i; dp[1]=2; dp[2]=2; dp[3]=4; for (i=4;i<=45;i++) dp[i]=dp[i-1]+dp[i-2]; int n; while (cin>>n) cout<<dp[n]<<endl; return 0;}
Ural 1225 Flags