poj 1953
来源:互联网 发布:天助网络 编辑:程序博客网 时间:2024/05/24 02:13
Problem:World Cup Noise
Description:韩国球迷用喇叭给运动员加油时,喇叭的使用时间不能超过2秒,否则喇叭就会坏掉,总的来说就是1不能连续出现。问给定一个正整数n,表示能有多少种方案吹响喇叭而不让喇叭损坏。
Solution:当n=1时,有0或1两种方案;当n=2时,有00,01,10三种方案;当n=3时可以分解成最后一秒是0和1来讨论,分析得知有五种方案;推广到n,知道f(n)=f(n-1)+f(n-2),代码很简单。
Code(C++):
#include<iostream>#include<cstdio>using namespace std;int main(){ int i,n,m,k=0; long long int a[55]; a[1]=2; a[2]=3; for(i=3;i<55;i++) a[i]=a[i-1]+a[i-2]; cin>>n; while(n--) { cin>>m; int ans=a[m]; cout<<"Scenario #"<<k+1<<":"<<endl<<ans<<endl<<endl; k++; } return 0;}
0 0
- POJ 1953
- poj 1953
- POJ 1953
- poj 1953
- poj 1953
- POJ-1953
- POJ 1953
- POJ-1953
- poj 1953
- poj-1953
- POJ 1953 DP
- poj 1953 Team Rankings
- POJ 1953 解题报告
- POJ
- poj
- POJ
- POJ
- poj
- 发布项目到tomcat的方法
- android make debug : (.ARM.exidx+0x0): error: undefined reference to '__aeabi_unwind_cpp_pr1'
- Centos下Zookeeper设置自启动
- Spring04
- hihoCode题目1
- poj 1953
- Google自己的下拉刷新组件SwipeRefreshLayout
- ftp-server
- HTML/CSS/JavaScript实现的2048小游戏
- LeetCode 121. Best Time to Buy and Sell Stock
- JSOI2016 独特的树叶 树的Hash判同构
- Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found
- Mybatis核心接口和类
- 表排序(思路一)