dp[i,j,k] is a max score of subarray b[i] ~ b[j]
if there are k boxes that have the same color as b[j] following b[j]
Those k boxes are from box[j + 1] ~ box[n], to simulate boxes with other colors are removed first.
"ABACA", dp[0,0,2]=dfs("A|AA")=9 # B,C are removed
Base case: if (j > i) then 0
Transition:
dp[i,j,k]=dp[i,j-1,0] + (k + 1)^2 # case 1
dp[i,p,k+1] + dp[p+1,j-1,0] # case 2
Case 1: drop box[j], remove k+1 boxes
Case 2: Try all breakpoints p, attach a[j] to a[p], i <= p < j, box[p] == box[j]
Answer: dp[0,n-1,0]
Time complexity: O(n^3) ~ O(n^4)
Space complexity: O(n^3)