描述
You are climbing a stair case. It takes n steps to reach to the top.
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
#include<iostream>
using namespace std;
int ClimbingStairs(int n)
{
if (n < 0)
return 0;
int pre2 = 1;
int pre1 = 1;
int current;
if (n == 0 || n == 1)
return 1;
for (int i = 0; i < n-1; i++)
{
current = pre2 + pre1;
pre2 = pre1;
pre1 = current;
}
return current;
}
int main()
{
int n = 5;
int kinds = ClimbingStairs(n);
cout << kinds << endl;
}