dp[l][r] = merge(dp[l][r-1], dp[l+1][r], compute(l, r))where
mergemerges the best results of all subarrays, and
compute(l, r)computes the value for
[l..r]. This guarantees that
dp[l][r]will track the best value from all subarrays. For this DP to work, we iterate by length of the subarray.