Beats 100%,
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(2^N  \u2217 N)\n\n\n\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```javascript []\n/**\n * @param {number[][]} grid\n * @return {number}\n */\nvar maxScore = function(grid) {\n      const n = grid.length;\n        const vals = new Map();\n        \n        // Collect the values and their row indices\n        for (let i = 0; i < n; i++) {\n            for (let h of grid[i]) {\n                if (!vals.has(h)) {\n                    vals.set(h, []);\n                }\n                vals.get(h).push(i);\n            }\n        }\n        \n        // Convert the Map to a sorted array\n        const valsArray = Array.from(vals.entries()).sort((a, b) => b[0] - a[0]);\n        \n        // Create a memoization cache\n        const memo = new Map();\n        \n        // Define the recursive function with memoization\n        const maxval = (i, mask) => {\n            if (i >= valsArray.length) {\n                return 0;\n            }\n            const key = `${i}-${mask}`;\n            if (memo.has(key)) {\n                return memo.get(key);\n            }\n            \n            // Option 1: Skip current value\n            let res = maxval(i + 1, mask);\n            \n            // Option 2: Include current value if the row is not used\n            for (let j of valsArray[i][1]) {\n                if (!(mask & (1 << j))) {\n                    res = Math.max(res, valsArray[i][0] + maxval(i + 1, mask | (1 << j)));\n                }\n            }\n            \n            memo.set(key, res);\n            return res;\n        };\n        \n        return maxval(0, 0);\n};\n```
['JavaScript']