[Al]算法:有n级阶梯,每次走1步或2步,最多有多少种走法

 @Filename   :   floor.c
*   @Author     :   Mr.Zhong
*   @Date       :   2018-11-02
*   @Description:   n级阶梯,每次走一步或2步,最多有多少种走法
*   @Analysis   :   斐波那契数列 -> 递归思维
***************************************************************/
#include <iostream>
 
using namespace std;
 
int getStepNum(int n)
{
    if(n < 0)
        return 0;
    if(n == 0 || n ==1 || n ==2)
        return n;
    if(n > 2)
        return getStepNum(n-1)+getStepNum(n-2);
}
 
int main()
{
    int levels;
    cout<<"Please enter how many levels of stairs :"<<endl;
    cin>>levels;
 
    int method = getStepNum(levels);
    cout<<"There are  "<<method<<" methods in total"<<endl;
    return 1;
}
 
--------------------- 
作者:Tobiu 在这里插入代码片
来源:CSDN 
原文:https://blog.csdn.net/localhostcom/article/details/83662968 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/wml45454545/article/details/84848649