码迷,mamicode.com
首页 > 其他好文 > 详细

第一轮 H

时间:2014-11-10 10:07:00      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:des   io   color   os   sp   for   on   2014   amp   

Flags
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
Submit Status

Description
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:
Problem illustration

Input
N, the number of the stripes, 1 ≤ N ≤ 45.

Output
M, the number of the ways to decorate the shop-window.

Sample Input
input	output

3

4

放第i个的时候,有两种方法:
      一、在第i 个上放上与i-1个相反的颜色(第i-1个是红色,则放白色,否则放红色);
      二、将第i-1个的颜色改成蓝色的;
综合上述的两种情况:ans[i]=ans[i-1]+ans[i-2]
/*************************************************************************
	> File Name: h.cpp
	> Author:yuan 
	> Mail: 
	> Created Time: 2014年11月09日 星期日 20时41分18秒
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
long long ans[50];
int n;
int main()
{  
    ans[1]=ans[2]=2;ans[0]=0;
    for(int i=3;i<=45;i++)
    {
        ans[i]=ans[i-1]+ans[i-2];
    }
    while(~scanf("%d",&n)){
        printf("%I64d\n",ans[n]);
    }
    return 0;
}


第一轮 H

标签:des   io   color   os   sp   for   on   2014   amp   

原文地址:http://blog.csdn.net/yuanchang_best/article/details/40954855

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!