几乎与此相同: find maximum sum of elements in an array such that not more than k elements are adjacent
除了我们可以选择的元素有 n 个限制。如何修改 DP 算法使其适用于此?
最佳答案
增加DP函数的新维度:
f[i, j, l]
- 前 i 个元素的最大总和,如果使用 j 个总元素和最后 l 个元素 在这笔款项中。
关于algorithm - 找到数组中 n 个元素的最大总和,使得不超过 k 个元素相邻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14745300/