Problem Description

東東有個嗜好,爬階梯不是一次走一階,就是一次走兩階。

換句話說,假設階梯有三階,那他有三種走法

一:第一步走一階,第二步走二階。

二:第一步走二階,第二步走一階。

三:全程都走一階。

這題要問你,假設階梯有n階,那東東有幾種走法?

Input Format

第一行有一個正整數n,0<n<100,表示階梯有n階。

Output Format

請輸出n個階梯有幾種走法。

Sample Input

1
2
5

Sample Output

1
2
8


-----*Problem from【ZeroJudge, An Online Judge System For Beginners

 

My Answer

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
#include<iostream>
using namespace std;
int main(void)
{
   unsigned long long f[100];
   f[0]=f[1]=1;
   for(int n=2; n<100; ++n){
      f[n]=f[n-1]+f[n-2];
   }
   while(cin>>n){
      cout<<f[n]<<endl;
   }
   return 0;
}


 


arrow
arrow
    全站熱搜

    兔老大 發表在 痞客邦 留言(2) 人氣()