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 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

3

output

4

Problem Source:

2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002

简单的递推,三种颜色的布,相邻的颜色不能相同,蓝色在红色与白色之间,则用1表示红色,2表示白色,Dp[i][j]表示第i个条纹的颜色为j是的状态数目,当j=1时,如果i-1的颜色为白色,则Dp[i][1]+=Dp[i-1][2],如果为蓝色,则取决于i-2的颜色为白色状态,所以Dp[i][1]=Dp[i-1][2]+Dp[i-2][2],则Dp[i][2]=Dp[i-1][1]+Dp[i-2][1].

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <deque>
#include <iostream>
#include <algorithm> using namespace std; long long Dp[50][3]; int main()
{
memset(Dp,0,sizeof(Dp)); Dp[1][1]=Dp[1][2]=1; for(int i=2;i<=45;i++)
{
Dp[i][1] =Dp[i-1][2]+Dp[i-2][2]; Dp[i][2] = Dp[i-1][1]+Dp[i-2][1];
} int n; while(~scanf("%d",&n))
{
cout<<Dp[n][1]+Dp[n][2]<<endl;
} return 0;
}

Flags-Ural1225简单递推的更多相关文章

  1. HDU 2085 核反应堆 --- 简单递推

    HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...

  2. 简单递推 HDU-2108

    要成为一个ACMer,就是要不断学习,不断刷题...最近写了一些递推,发现递推规律还是挺明显的,最简单的斐波那契函数(爬楼梯问题),这个大家应该都会,看一点稍微进阶了一点的,不是简单的v[i] = v ...

  3. UVA10943简单递推

    题意:      给你两个数字n,k,意思是用k个不大于n的数字组合(相加和)为n一共有多少种方法? 思路:       比较简单的递推题目,d[i][j]表示用了i个数字的和为j一共有多少种情况,则 ...

  4. NBUT 1028 该减肥了(简单递推)

    [1028] 该减肥了 时间限制: 1000 ms 内存限制: 65535 K 问题描述 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥.Teach ...

  5. 2018.06.29 NOIP模拟 1807(简单递推)

    1807 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出一个由数字('0'-'9')构成的字符串.我们说一个子序列是好的,如果他的每一位都是 1.8.0.7 ,并且这四个数字按照 ...

  6. dp的简单递推笔记1

    (1)转自rockZ的博文 UVa 10328 - Coin Toss (递推) 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手. ...

  7. POJ_2478 Farey Sequence 【欧拉函数+简单递推】

    一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...

  8. <每日一题> Day5:简单递推两题

    原题链接 参考代码: #include <iostream> using namespace std; typedef long long ll; + ; ll dp[maxn]; int ...

  9. hdu 5273 Dylans loves sequence 逆序数简单递推

    Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...

随机推荐

  1. Python 中的urlencode和urldecode

    python中的urlencode与urldecode 发表于2013/11/13 16:04:09  79983人阅读 分类: python 当url地址含有中文,或者参数有中文的时候,这个算是很正 ...

  2. .net资源链接

    http://aspalliance.com/ http://www.hotscripts.com/ http://www.dotnet247.com http://stackoverflow.com ...

  3. Python开发程序:选课系统-改良版

    程序名称: 选课系统 角色:学校.学员.课程.讲师要求:1. 创建北京.上海 2 所学校2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开3. ...

  4. C++学习笔记 指针与引用

    指针与引用  1. 指针 (1) 指针是一个变量(实体),存储的是一个地址,指向内存的一个存储单元,指针可以为空 (2) 指针可以为空,在声明定义时可以不初始化 (3) 指针在初始化之后可以重新指向其 ...

  5. 2.C语言中的关键字

    1.auto 修饰局部变量,编译器默认所有局部变量都是用auto来修饰的,所以在程序中很少见到. 2.static 它作用可大了,除了可以修饰变量,还可以修饰函数,修饰变量,改变其作用域和生命周期,修 ...

  6. Python--While循环语句

    Python While循环语句 Python 编程中 while 语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务.其基本形式为: while 判断条件: 执行语句 ...

  7. bindOrg函数

    @param params {userId 用户ID, orgcode 机构代码, defaultOrgcode 默认机构代码, defaultOcid 默认银行代码, flag 1=取所有中心(默认 ...

  8. Redis在Linux下的安装和启动和配置

    第一步:下载Redis安装包,下载版本:3.0.5 在所在目录右键打开终端输入命令: wget http://download.redis.io/releases/redis-3.0.5.tar.gz ...

  9. 经历alidns在国外的严重延时

    有个域名,是在国外1und1申请的,但dns的解析,国外的空间的功能弱爆了. 之前是放在dnspod,后来又试过dnspod的海外, 最后放回alidns,之前一直都很好的. 这2天国内没问题,在德国 ...

  10. TIJ——Chapter Five:Initialization & Cleanup

    Method overloading |_Distinguishing overloaded methods If the methods hava the same name, how can Ja ...