這是一道基礎的動態規劃題目
class Solution {
private:
vector<int> memo;
int calWays( int n ){
if( n == 0 || n == 1 )
return 1;
if( memo[n] == -1 )
memo[n] = calWays(n-1) + calWays(n-2);
//可以由前一個跳過去,可以由前兩個跳過去
return memo[n];
}
public:
int climbStairs(int n) {
memo = vector<int>(n+1,-1);
return calWays(n);
}
};