简答题 偏难
#22196

阅读程序(2) # include <iostream> # include <vector> using namespace std ; int comput…

阅读程序(2)

#include <iostream>
#include <vector>
using namespace std;
int compute(vector<int> &cost) {
    int n = cost.size();
    vector<int> dp(n + 1, 0);
    dp[1] = cost[0];
    for (int i = 2; i <= n; i++) {
      dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i - 1];
   }
   return min(dp[n], dp[n - 1]);
}
int main() {
    int n;
    cin >> n;
    vector<int> cost(n);
    for (int i = 0; i < n; i++) {
        cin >> cost[i];
    }
    cout << compute(cost) << endl;
    return 0;
}
未登录也能判分,登录后才会记录
答案与解析
正确答案:(缺答案,待补录)
这道题暂未补解析。