|
| 1 | +<p>You are given several <code>boxes</code> with different colors represented by different positive numbers.</p> |
| 2 | + |
| 3 | +<p>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 (i.e., composed of <code>k</code> boxes, <code>k >= 1</code>), remove them and get <code>k * k</code> points.</p> |
| 4 | + |
| 5 | +<p>Return <em>the maximum points you can get</em>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> boxes = [1,3,2,2,2,3,4,3,1] |
| 12 | +<strong>Output:</strong> 23 |
| 13 | +<strong>Explanation:</strong> |
| 14 | +[1, 3, 2, 2, 2, 3, 4, 3, 1] |
| 15 | +----> [1, 3, 3, 4, 3, 1] (3*3=9 points) |
| 16 | +----> [1, 3, 3, 3, 1] (1*1=1 points) |
| 17 | +----> [1, 1] (3*3=9 points) |
| 18 | +----> [] (2*2=4 points) |
| 19 | +</pre> |
| 20 | + |
| 21 | +<p><strong class="example">Example 2:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> boxes = [1,1,1] |
| 25 | +<strong>Output:</strong> 9 |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p><strong class="example">Example 3:</strong></p> |
| 29 | + |
| 30 | +<pre> |
| 31 | +<strong>Input:</strong> boxes = [1] |
| 32 | +<strong>Output:</strong> 1 |
| 33 | +</pre> |
| 34 | + |
| 35 | +<p> </p> |
| 36 | +<p><strong>Constraints:</strong></p> |
| 37 | + |
| 38 | +<ul> |
| 39 | + <li><code>1 <= boxes.length <= 100</code></li> |
| 40 | + <li><code>1 <= boxes[i] <= 100</code></li> |
| 41 | +</ul> |
0 commit comments