If it is necessary to divide the array into exactly k subsegments, then the second parameter is simply added in dynamic programming - how many segments to split into.
That is, now we will consider the following dp:
dp[i][j] is the answer for the first i elements, if we split them into exactly j segments.
Watch out for invalid states.
The recalculation of the dynamics is the same, but taking into account the second parameter. That is, counting dp[i][k] and sorting through the left border of the last subsegment j, we recalculate dp[i][k] through dp[j - 1][k - 1] and the value of the segment [j;i].