Flags-Ural1225简单递推
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简单递推的更多相关文章
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- 简单递推 HDU-2108
要成为一个ACMer,就是要不断学习,不断刷题...最近写了一些递推,发现递推规律还是挺明显的,最简单的斐波那契函数(爬楼梯问题),这个大家应该都会,看一点稍微进阶了一点的,不是简单的v[i] = v ...
- UVA10943简单递推
题意: 给你两个数字n,k,意思是用k个不大于n的数字组合(相加和)为n一共有多少种方法? 思路: 比较简单的递推题目,d[i][j]表示用了i个数字的和为j一共有多少种情况,则 ...
- NBUT 1028 该减肥了(简单递推)
[1028] 该减肥了 时间限制: 1000 ms 内存限制: 65535 K 问题描述 由于长期缺乏运动,Teacher Xuan发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥.Teach ...
- 2018.06.29 NOIP模拟 1807(简单递推)
1807 题目背景 SOURCE:NOIP2015-SHY-2 题目描述 给出一个由数字('0'-'9')构成的字符串.我们说一个子序列是好的,如果他的每一位都是 1.8.0.7 ,并且这四个数字按照 ...
- dp的简单递推笔记1
(1)转自rockZ的博文 UVa 10328 - Coin Toss (递推) 题意:给你一个硬币,抛掷n次,问出现连续至少k个正面向上的情况有多少种. 原题中问出现连续至少k个H的情况,很难下手. ...
- POJ_2478 Farey Sequence 【欧拉函数+简单递推】
一.题目 The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbe ...
- <每日一题> Day5:简单递推两题
原题链接 参考代码: #include <iostream> using namespace std; typedef long long ll; + ; ll dp[maxn]; int ...
- hdu 5273 Dylans loves sequence 逆序数简单递推
Dylans loves sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem ...
随机推荐
- django对数据查询结果进行排序的方法
在你的 Django 应用中,你或许希望根据某字段的值对检索结果排序,比如说,按字母顺序. 那么,使用 order_by() 这个方法就可以搞定了. ? 1 2 >>> Publis ...
- jquery 追加元素的方法
append() 方法在被选元素的结尾插入内容. 在里面 prepend() 方法在被选元素的开头插入内容. 在里面 after() 方法在被选元素之后插入内容. 在外面before() 方法在被选元 ...
- JavaScript第一天 改变DIV的样式
onmouseover 当鼠标移到这个对象之上时响应 onmouseout 当鼠标移出这个对象之上时响应 document.getElementById('id') 获取id的元素并可以做一些操作 ...
- Ubuntu 14.04 编译安装 husky
简介 Husky是一个大数据分布式开发框架,用C++开发,因为粗粒度(coarse-grained)平台(如Spark,Hadoop,Flink)MR耗时太大,然后细粒度(fine-grained)平 ...
- C# 文件操作笔记
C#中的文件操作 文件操作中的常见类: 静态类 File类:提供很多静态方法,用于移动.复制和删除文件. Directory类:用于移动.复制和删除目录. Path类:用于处理与路径相关的操作. 实例 ...
- Python模拟删除字符串两边的空白
目标: 1.使用string模块的whitespace 2.删除左边.右边以及两边的空白 代码如下: [root@localhost python]# cat rmspace.py #!/usr/bi ...
- jS正则和WEB框架Django的入门
JS正则 -test 判断字符串是否符合规定的正则表达式 -exec 获取匹配的数据 test的例子: 从上述的例子我们可以看出,如果rep.test匹配到了就返回true,否则返回false exe ...
- RDIFramework.NET ━ .NET快速信息化系统开发框架 ━ 工作流程组件介绍
RDIFramework.NET ━ .NET快速信息化系统开发框架 工作流程组件介绍 RDIFramework.NET,基于.NET的快速信息化系统开发.整合框架,给用户和开发者最佳的.Net框架部 ...
- xl2tp部署
参考 http://blog.51yip.com/linux/1795.html 说到VPN,就会想到google,满心的疼.以前写过一篇关于vpn的文单,请参考:centos5.5 vpn 安装配置 ...
- App.domain http->https
App.domain = `${location.origin}/toa-mgw/rest/gateway`.replace(/http:\/\//, 'https://');