// test14.cpp : 定義控制台應用程序的入口點。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<cctype>
#include <vector>
#include<exception>
#include <initializer_list>
using namespace std;
class Solution {
public:
int jumpFloorII(int number) {
//第一種方法 算法復雜度太高
int target = 0;
if (number < 2)
return 1;
for (int i = number - 1; i >= 0;i--)
target +=jumpFloorII(i);
return target;
//第二種方法 節省空間,時間快
}
};
int main()
{
int num ;
Solution so;
while (cin>>num)
{
cout << "所求結果是: " ;
cout << so.jumpFloorII(num) << endl;
cout << endl;
}
return 0;
}
注意:其方法和一次只能跳一個或者兩個台階類似,第一次跳1個,還有f(n-1)個方法;第一次跳2個,還有f(n-2)中方法;第一次跳3個,還有f(n-3)種方法。。。。。。。。。。。。。累加即可。