Bitmask DP mask of used rows
\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        vals = {}\n        for i in range(n):\n            for 
```\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        n = len(grid)\n        vals = {}\n        for i in range(n):\n            for h in grid[i]:\n                if h not in vals:\n                    vals[h] = []\n                vals[h].append(i)\n        vals = list(vals.items())\n        @lru_cache(maxsize = None)\n        def maxval(i, mask):\n            if i >= len(vals):\n                return 0\n            res = maxval(i + 1, mask)\n            for j in vals[i][1]:\n                if not mask & (1 << j):\n                    res = max(res, vals[i][0] + maxval(i + 1, mask | (1 << j)))\n            return res\n        return maxval(0, 0)\n```
['Python']