#3276
Select Cells in Grid With Maximum Score
hard · 15.6% accepted · 226 likes · top 0%
array · dynamic programming · bit manipulation · matrix · bitmask
Description
You are given a 2D matrix grid consisting of positive integers.
You have to select one or more cells from the matrix such that the following conditions are satisfied:
- No two selected cells are in the same row of the matrix.
- The values in the set of selected cells are unique.
Your score will be the sum of the values of the selected cells.
Return the maximum score you can achieve.
Solution