首页 > 代码库 > 第一轮 H
第一轮 H
FlagsTime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64uSubmit StatusDescriptionOn 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 illustrationInputN, the number of the stripes, 1 ≤ N ≤ 45.OutputM, the number of the ways to decorate the shop-window.Sample Inputinput output34放第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; }
第一轮 H
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。