题解
2023-09-01 16:45:37
发布于:广东
3阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> skill(n);
for (int i = 0; i < n; i++) { cin >> skill[i]; }
vector<int> dp(n, -1);
for (int i = 0; i < n; i++) {
int cur = skill[i];
for (int j = i; j >= (i - k + 1) && ~j; j--) {
cur = max(cur, skill[j]);
if (j > 0) {
dp[i] = max(dp[i], dp[j - 1] + (cur * (i - j + 1)));
} else {
dp[i] = max(dp[i], cur * (i - j + 1));
}
}
}
cout << dp[n - 1] << endl;
}
这里空空如也
有帮助,赞一个