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