Timus 1225. Flags dp

1225. Flags
Time Limit: 1.0 second
Memory Limit: 16 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

input 
3

output

4

 

 

 

 

discuss裏有人這麼說:

use fibonacci
1,1,2,3,5,8,13...

answer = fibonacci(3)*2;

不明白……但這麼做答案是對的。

我用的是dp

 

 

發佈了20 篇原創文章 · 獲贊 8 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章