组合题
#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;}
(1)判断题原卷 1.5 分

当输入的 cost 数组为 {10,15,20}\{10, 15, 20\} 时,程序的输出为 1515。( )

填写答案
(2)判断题原卷 1.5 分

如果将 dp[i-1] 改为 dp[i-3],程序可能会产生编译错误。( )

填写答案
(3)判断题原卷 2 分

(2 分)程序总是输出 cost 数组中最小的元素。( )

填写答案
(4)单选题原卷 3 分

当输入的 cost 数组为 {1,100,1,1,1,100,1,1,100,1}\{1, 100, 1, 1, 1, 100, 1, 1, 100, 1\} 时,程序的输出为( )。

填写答案
(5)单选题原卷 4 分

(4 分)如果输入的 cost 数组为 {10,15,30,5,5,10,20}\{10, 15, 30, 5, 5, 10, 20\},程序的输出为( )。

填写答案
(6)单选题原卷 3 分

若将代码中的 min(dp[i-1], dp[i-2]) + cost[i-1] 修改为 dp[i-1] + cost[i-2],输入 cost 数组为 {5,10,15}\{5, 10, 15\} 时,程序的输出为( )。

填写答案