ural1225-Flags-动态规划
来源:互联网 发布:ghost远控源码 编辑:程序博客网 时间:2024/05/22 04:49
1225. Flags
Time limit: 1.0 second
Memory limit: 64 MB
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:
Input
N, the number of the stripes, 1 ≤ N ≤ 45.
Output
M, the number of the ways to decorate the shop-window.
Sample
3
4
Problem Source: 2002-2003 ACM Central Region of Russia Quarterfinal Programming Contest, Rybinsk, October 2002
Tags: dynamic programming
)Difficulty: 56 Printable version Submit solution Discussion (17)
My submissions All submissions (17982) All accepted submissions (7478) Solutions rating (6251)
My submissions All submissions (17982) All accepted submissions (7478) Solutions rating (6251)
我太弱了,看了如此多稀奇古怪说不清楚的题解。。。。
还是自己想出来了,尽管题目很简单。。。
但好像我这个说的清楚一些
//该题//1.注意long long啊!斐波那契数列到第45个正好爆int!//2.dp[i]=dp[i-1]+dp[i-2]这个方程是这样得到的!//原因:①当n=i-1时,最后一块旗子的颜色不是蓝色//②所以当n=i时,最后一块旗子的颜色也不是蓝色,且若从n=i-1时得到该旗子,则最后一面旗子与n=i-1的最后一面颜色也不一样//因而dp[i]可由dp[i-1]得到//③当n=i时,倒数第二块旗子的颜色为蓝(即与②中的倒数第二块为红白颜色不一样),此时对最后一面旗子与倒数第三面旗子一样,//因而dp[i]可由dp[i-2]得到#include <iostream>#include <cstdio>using namespace std;const int maxnum=45;typedef long long ll;ll dp[maxnum]={2,2,4};int main(){ int n; cin>>n; for(int i=3;i<45;++i) dp[i]=dp[i-1]+dp[i-2]; cout<<dp[n-1]; return 0;}
- ural1225-Flags-动态规划
- URAL1225 Flags, DP
- Flags-Ural1225简单递推
- URAL 1225 Flags (DP动态规划)
- Ural1225(数学)
- 动态规划!!!动态规划!!!
- flags ()
- Flags
- Flags
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- 动态规划
- USB驱动之几个重要结构体分析
- Ubuntu 11.04 下安装配置 JDK 7
- 转载请注明出处: http://www.blogjava.net/zh-weir/archive/2013/08/14/402821.html
- 百度如何识别原创
- 士兵杀敌(四)
- ural1225-Flags-动态规划
- Ubuntu下如何解压缩zip,tar,tar.gz,tar.bz2文件
- The Chain Of Responsibility Pattern
- Ubuntu 12.04下安装VMware Tools
- win7 64bit openni2+vs2012安装
- 11.26C语言----指针函数/指向指针的指针
- [Java] 数组-05 binarySearch / TestArrayCopy
- poj 1018 Communication System_贪心
- 30天自制操作系统笔记(三)