标签:++ 初始 [] http com script public https ==
最简单的动态规划
假设f[i]表示爬到第i层有几种爬法
那么状态转移方程为:f[i] = f[i-1] + f[i-2]
初始条件显然是:f[1]=1,f[2] = 2;
class Solution {
public int climbStairs(int n) {
if (n == 1) return 1;
int f[] = new int[n];
f[0] = 1;
f[1] = 2;
for (int i = 2; i < n; i++) {
f[i] = f[i - 1] + f[i - 2];
}
return f[n - 1];
}
}
标签:++ 初始 [] http com script public https ==
原文地址:https://www.cnblogs.com/acbingo/p/9368882.html