Remove Boxes
You are given several boxes with different colors represented by different positive numbers.
You may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color, composed of k boxes where k >= 1, remove them, and get k * k points.
Return the maximum points you can get.
Example 1
Input
boxes = [1,3,2,2,2,3,4,3,1]Output
23Removing the three 2s, then the 4, then the three 3s, then the two 1s gives 9 + 1 + 9 + 4 = 23 points.
Example 2
Input
boxes = [1,1,1]Output
9All three boxes have the same color, so removing them together gives 3 * 3 = 9 points.
Constraints
- 1 <= boxes.length <= 100
- 1 <= boxes[i] <= 100