Flags Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status 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: 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 input output 3 4 放第i个的时候,有两种方法: 一、在第i 个上放上与i-1个相反的颜色(第i-1个是红色,则放白色,否则放红色); 二、将第i-1个的颜色改成蓝色的; 综合上述的两种情况:ans[i]=ans[i-1]+ans[i-2] /************************************************************************* > File Name: h.cpp > Author:yuan > Mail: > Created Time: 2014年11月09日 星期日 20时41分18秒 ************************************************************************/ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<cmath> using namespace std; long long ans[50]; int n; int main() { ans[1]=ans[2]=2;ans[0]=0; for(int i=3;i<=45;i++) { ans[i]=ans[i-1]+ans[i-2]; } while(~scanf("%d",&n)){ printf("%I64d\n",ans[n]); } return 0; }
时间: 2024-10-10 08:48:51