
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Do a DP, where dp(i, j) is the answer for the subarray arr[i]..arr[j].
For each possible way to partition the subarray i <= k < j, the answer is max(arr[i]..arr[k]) * max(arr[k+1]..arr[j]) + dp(i, k) + dp(k+1, j).