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 ...
随机推荐
- 关于JavaScript的判断语句(2)
上一篇描述的都是一些通过条件判断来执行,符合条件下面的代码块,达到对动作的反应效果 这篇将描述的是for. for/in. while. do/while循环语句. for语句: for(i=0,i& ...
- 游记——noip2016
2016.11.18 (day 0) 呆在家. 悠闲地呆在家.. 明后天可能出现的错误: 1)没打freopen.打了ctime: 2)对拍程序忘记怎么写了...忘记随机化种子怎么写了: 3)不知道厕 ...
- "undefined method `root' for nil:NilClass" error when using "pod install" 解决办法
如果pod undate 的时候报错"undefined method `root' for nil:NilClass" error when using "pod in ...
- Linux下查看Nginx安装目录、版本号信息?
Linux环境下,怎么确定Nginx是以那个config文件启动的? 输入命令行: ps -ef | grep nginx 摁回车,将出现如下图片: master process 后面的就是 ngi ...
- awk sed 总结
Awk总结笔记 介绍 90年代 new awk :nawk Linux 的是gawk 我们简化awk 用法 # awk [options ] ‘scripts’ file1 file2 .... # ...
- linux vim
wq 强制性写入文件并退出.即使文件没有被修改也强制写入,并更新文件的修改时间.x 写入文件并退出.仅当文件被修改时才写入,并更新文件修改时间,否则不会更新文件修改时间.
- Oracle常用操作——创建表空间、临时表空间、创建表分区、创建索引、锁表处理
摘要:Oracle数据库的库表常用操作:创建与添加表空间.临时表空间.创建表分区.创建索引.锁表处理 1.表空间 ■ 详细查看表空间使用状况,包括总大小,使用空间,使用率,剩余空间 --详细查看表空 ...
- 鸟哥linux私房菜基础篇
1)注销:exit2)指令太长:命令太长的时候,可以使用反斜杠 (\) 来跳脱[Enter]符号,使挃令连续到下一行3)系统语言显示和设置命令:echo $LANG,显示当前系统语言:简体中文zh_C ...
- 今天学了递归,感觉好复杂啊/(ㄒoㄒ)/~~
honio塔思路: 第一步 把A上的n-1个圆盘借助C移到B上: 第二步 把A上的一个圆盘移到C上: 第三步 把B上的n-1个圆盘借助A移到C上. 这显然符合递归的两个条件: ①具备边界条件:只有1个 ...
- android studio 项目迁移编码问题
关于编码问题.首先,eclipse上一般我们文件默认都设置成UTF-.对于迁移到Android Studio显示不存在乱码问题. 部分同学可能会遇到一个问题:代码中的中文(包括注释的中文),在编译时跳 ...