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. xcode8升级后问题总汇

    一.注释快捷键无法使用 command + / 快捷键无法使用,在终端执行以下命令,然后重启Xcode即可.   1 sudo /usr/libexec/xpccachectl 二.注释快捷键 Xco ...

  2. Ueditor百度网页编辑器开发者版java utf-8的使用

    index.jsp主要代码: <html> <head> <title>网页编辑器</title> <script type="text ...

  3. C# 文件操作笔记

    C#中的文件操作 文件操作中的常见类: 静态类 File类:提供很多静态方法,用于移动.复制和删除文件. Directory类:用于移动.复制和删除目录. Path类:用于处理与路径相关的操作. 实例 ...

  4. MQTT——服务器搭建(一)

    MQTT介绍 MQTT,是IBM推出的一种针对移动终端设备的基于TCP/IP的发布/预订协议,可以连接大量的远程传感器和控制设备: 轻量级的消息订阅和发布(publish/subscribe)协议 建 ...

  5. JavaScript:异步 setTimeout

    setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式. function showDate(){ var date=new Date(); console.log(date); } ...

  6. lua自定义迭代器

    迭代器 http://www.tutorialspoint.com/lua/lua_iterators.htm 迭代器能够让你遍历某个集合或者容器中的每一个元素. 对于lua来说, 集合通常指代 ta ...

  7. python-study1 in hubei

    1.安装好python后要配置环境变量(C:\Python27\Scripts---能找到pip.exe和easy_install.exe和C:\Python27---能找到python.exe) 2 ...

  8. 数据库触发器inserted和deleted详解

    create trigger updateDeleteTime on user for update as begin   update user set UpdateTime=(getdate()) ...

  9. Javascript-9-1-OOP-5-链式调用

    <html lang="en"> <head> </head> <body> <div class="" ...

  10. swift基础:第二部分:函数和闭包

    今天本来想利用上午的时间本来打算将swift基础部分学习完的,不巧的是,后台来和我讨论用户评价的接口,讨论过后,商讨出一种可行的方案,十几分钟时间过去了,我拿到将接口介入到已经完成的页面中,完美,终于 ...