1225. Flags
Time 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
Test instructions: Coloring problem. Adjacent colors can not be the same, blue can only appear between red white or white red.
Parsing: recursion.
Consider the color of the position I: if red or white, you only need to add a white or red in the back of the i-1, if the blue, then the i-1 will be red or white, you only need to add red or white in the back of the i-2.
Must be a long long, otherwise WA on Test 12.
AC Code:
#include <cstdio>long long F[50];int main () { f[1] = f[2] = 2; for (int i=3; i<=50; i++) f[i] = F[i-1] + f[i-2]; int n; while (scanf ("%d", &n) ==1) { printf ("%lld\n", F[n]); } return 0;}
URAL 1225. Flags (DP)