题解 | #最小花费爬楼梯#
最小花费爬楼梯
https://www.nowcoder.com/practice/9b969a3ec20149e3b870b256ad40844e
#include <iostream> using namespace std; const int N = 100010; int f[N]; int cost[N]; int main() { int n; cin >> n; for(int i = 1; i <= n; i ++) cin >> cost[i]; f[1] = cost[1], f[2] = cost[2]; for(int i = 3; i <= n + 1; i ++){ f[i] = min(f[i - 1] + cost[i], f[i - 2] + cost[i]); } cout << f[n + 1] << endl; return 0; }