Ural 1225 Flags

Source: Internet
Author: User

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:
    1. Stripes of the same color cannot is placed next to all other.
    2. 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
input Output
3
4
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.