Ural_Dynamic Programming Problems_1225-Flags
2015-01-21 07:55
190 查看
Description
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
input | output |
---|---|
3 | 4 |
Tags: dynamic programming (
hide tags for unsolved problems
)
Difficulty: 50
一道简单的递推题,当n=1时m=2,当n=2时m=2,当n=3时m=4,当n=4时m=6......可以推出当n>=3时a
=a[n-1]+a[n-2],由此代码很容易就写出来了。
代码
#include <iostream> using namespace std; int main() { int n,i; long long a[50]; a[1]=2; a[2]=2; for(i=3; i<50; i++) a[i]=a[i-1]+a[i-2]; cin>>n; cout<<a <<endl; return 0; }
相关文章推荐
- Ural 1225 Flags
- two simple problems solved by dynamic programming
- The journey of Ural dynamic programming
- 递推DP URAL 1225 Flags
- URAL 1225. Flags
- URAL1225——DP——Flags
- ural 1225.Flags
- Ural_1225 Flags
- ural1225-Flags-动态规划
- URAL 1225 Flags 简单DP,一重循环
- URAL 1225 Flags (DP动态规划)
- URAL 1225(Flags)简单递推
- ural 1225. Flags
- URAL 1225-Flags(规律递推)
- URAL1225 Flags, DP
- URAL-1225 Flags
- ural 1225 Flags
- Ural 1225 Flags(DP)
- ural 1225.Flags(简单dp)
- 论文读书笔记-Approximate Dynamic Programming for Storage Problems