546. Remove Boxes Hard

@problem@discussion
#Array#Dynamic Programming#Memoization



1/**
2 * [546] Remove Boxes
3 *
4 * You are given several boxes with different colors represented by different positive numbers.
5 * 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 k boxes, k >= 1), remove them and get k * k points.
6 * Return the maximum points you can get.
7 *  
8 * Example 1:
9 * 
10 * Input: boxes = [1,3,2,2,2,3,4,3,1]
11 * Output: 23
12 * Explanation:
13 * [1, 3, 2, 2, 2, 3, 4, 3, 1] 
14 * ----> [1, 3, 3, 4, 3, 1] (3*3=9 points) 
15 * ----> [1, 3, 3, 3, 1] (1*1=1 points) 
16 * ----> [1, 1] (3*3=9 points) 
17 * ----> [] (2*2=4 points)
18 * 
19 * Example 2:
20 * 
21 * Input: boxes = [1,1,1]
22 * Output: 9
23 * 
24 * Example 3:
25 * 
26 * Input: boxes = [1]
27 * Output: 1
28 * 
29 *  
30 * Constraints:
31 * 
32 * 	1 <= boxes.length <= 100
33 * 	1 <= boxes[i] <= 100
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/remove-boxes/
39// discuss: https://leetcode.com/problems/remove-boxes/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn remove_boxes(boxes: Vec<i32>) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_546() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.