下列代码是一维数组优化 0/1 背包的核心片段,执行后 dp[8] 的输出结果是( )。
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int w = 3, v = 5, W = 8;
int dp[9] = {0};
for (int c = W; c >= w; c--)
dp[c] = max(dp[c], dp[c - w] + v);
cout << dp[8] << endl;
return 0;
}
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析