3276. Select Cells in Grid With Maximum Score Hard

@problem@discussion
#Array#Dynamic Programming#Bit Manipulation#Matrix#Bitmask



1/**
2 * [3276] Select Cells in Grid With Maximum Score
3 *
4 * You are given a 2D matrix grid consisting of positive integers.
5 * You have to select one or more cells from the matrix such that the following conditions are satisfied:
6 * 
7 * 	No two selected cells are in the same row of the matrix.
8 * 	The values in the set of selected cells are unique.
9 * 
10 * Your score will be the sum of the values of the selected cells.
11 * Return the maximum score you can achieve.
12 *  
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">grid = [[1,2,3],[4,3,2],[1,1,1]]</span>
16 * Output: <span class="example-io">8</span>
17 * Explanation:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/29/grid1drawio.png" />
19 * We can select the cells with values 1, 3, and 4 that are colored above.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">grid = [[8,7,6],[8,3,2]]</span>
24 * Output: <span class="example-io">15</span>
25 * Explanation:
26 * <img alt="" src="https://assets.leetcode.com/uploads/2024/07/29/grid8_8drawio.png" style="width: 170px; height: 114px;" />
27 * We can select the cells with values 7 and 8 that are colored above.
28 * </div>
29 *  
30 * Constraints:
31 * 
32 * 	1 <= grid.length, grid[i].length <= 10
33 * 	1 <= grid[i][j] <= 100
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/select-cells-in-grid-with-maximum-score/
39// discuss: https://leetcode.com/problems/select-cells-in-grid-with-maximum-score/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn max_score(grid: Vec<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_3276() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.