题目
- 每个数组中的方案可以重复选择,递归模型为从左往右遍历,要或者不要的情况
- ...........
function process(arr, index, restLen) {
// 绳子没有剩余
if (restLen === 0) {
return 0;
}
// 找不到满足的方案了
if (index == arr.length) {
return 0;
}
// 可能性1:不要当前方案
let p1 = process(arr, index + 1, restLen);
// 当前方案长度必须小于等于绳子剩余长度
let p2 = -Infinity;
if (arr[i][0] <= restLen) {
p2 = arr[i][1] + process(arr, index, restLen - arr[i][0]);
}
return Math.max(p1, p2);
}