dp
with -1 to indicate uncalculated subproblems.solve
that takes the starting and ending indices of the current subarray.solve
for the appropriate subarray and update the maximum score.solve
with the full range of the array and return the result as the final answer.