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 ...
随机推荐
- PHP preg_replace使用例子
将 qwer://xxx/545/0 替换为 qwer://trading_system_xxx/0/545 $str = '<a href="qwer://xxx/545/0&quo ...
- java中字节流与字符流的区别
字节流 在I/O类库中,java.io.InputStream和java.io.OutputStream分别表示字节输入流和字节输出流,它们都是抽象类,不能实例化,数据流中的最小单位是字节,所以叫做字 ...
- 在eclipse中使用正则表达式进行搜素
- 在四合院里写code是什么体验(非拉仇恨)
我工作的地点在一个幽静的四合院,后海边上.每次出了地铁还要走长长的十分钟的胡同,经过恬静的老人,嬉戏的小孩,还有就是长年不缺的游客.很多次,在夕阳将下未下时五六点的时候,小胡同里老人拿着小马扎,一群小 ...
- idea使用心得(4)-踩过的坑
1.非法的表达式开始 / 需要';' / 未结束的字符串文字 表现形式: 原因/解决: 这个一定是文件编码问题:依次检查setting中的file Encodings 中的IDE ...
- GIT 配置管理
git版本控制开发流程小结笔记(一) 收藏 何良瑞Nyanko君 ...
- 使用openvswitch 和dnsmasq来实现虚拟机网络隔离
openvswicth : 开源的网络虚拟化软件,可以划分vlan隔离虚拟机,做流量控制 dnsmasq:小心的dns,dhcp服务器 安装openvswicth wget http://openv ...
- vmware centos nat模式下连不上网络解决办法
简单来讲,当你创建一台虚拟机时,VMware为你虚拟了三种接入网络的方式:桥连接,NAT,使用主机网络,Vmware 10中默认对应 VMnet0,VMnet1,VMnet8 . 当选择桥连接方 ...
- 快速查找和你聊天人的IP和具体的物理所在地址
附言 : 对于中秋佳节没有回家也没有外出的我,亦然选择闭关.本来是打算把这个公众号作为测试号的.但是发现这个号已经有注册有一年多了,怪可惜的!所以就用来发些教程图文,供给大家共同学习,也对自己进行不定 ...
- 003-常用的Meta标签写法和作用
页面关键词<meta name="keywords" content="your,tags"/> 页面描述<meta name="d ...