我上leetcode上试了下 可以通过
class Solution {
public int maxSumAfterPartitioning(int[] arr, int k) {
final int n = arr.length;
int[] dp = new int[n + 1];
for (int i = 1; i <= n; ++i) {
for (int j = 1, m = 0; j <= i && j <= k; ++j) {
m = Math.max(m, arr[i - j]);
dp[i] = Math.max(dp[i], dp[i - j] + m * j) ;
}
}
return dp[n];
}
}