Flags-Ural1225简单递推
来源:互联网 发布:优麒麟下安装windows 编辑:程序博客网 时间:2024/05/18 11:22
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简单递推
- URAL1225 Flags, DP
- ural1225-Flags-动态规划
- URAL 1225(Flags)简单递推
- URAL 1225-Flags(规律递推)
- Ural1225(数学)
- UVA10943简单递推
- hdu2501 简单递推
- 简单递推
- 简单递推
- 简单递推
- 简单递推
- 简单递推
- ural 1225.Flags(简单dp)
- UVa 11000 简单递推
- hdu 2046 简单递推
- poj 2081 简单递推
- HDU 2190 简单递推
- [神经网络]1.6-Using neural nets to recognize handwritten digits-Implementing our network to classify(翻译)
- getParameterValues使用
- Android开发笔记(六十六)自定义对话框
- class has no initializers
- div的float:left与span标签
- Flags-Ural1225简单递推
- Scala中的String.split函数
- 在vmware fusion 8 for Mac上安装windows 7 64bit
- HashMap的工作原理
- 随笔
- RxJava 创建操作符form
- maven【2】(maven问题)
- 用CocoaPods做iOS程序的依赖管理
- JS格式化/压缩JSON数据