DP with Bitmasking O(k*2^11) ✅✅✅
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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int solve(int i, int n , vector<int>&ashu , unordered_map<int,vector<int>>&mp , int mask , vector<vector<int>>&dp)\n    {\n        if(i>=n)return 0;\n        if(dp[i][mask]!=-1)return dp[i][mask];\n        // ab smjhiye\n        // i is representing the index of the ashu vector ,\n        // mask is representing whether the particular row in which mp[ashu[i]] happens is empty or not \n        // So lets check please \n        int ans =0 ;\n        for(auto j : mp[ashu[i]])\n        {\n            if((mask & (1<<j)) == 0)\n            {\n                ans = max(ans ,  ashu[i] + solve(i+1 , n, ashu , mp , mask | (1<<j) , dp) );\n            }\n        }\n        ans = max(ans , solve(i+1 , n , ashu , mp ,mask , dp));\n        return dp[i][mask] = ans;\n    }\n    int maxScore(vector<vector<int>>& grid) {\n        unordered_set<int>st;\n        int n =grid.size();\n        int m = grid[0].size();\n        for(auto i : grid)\n        {\n            for(auto j : i)\n            {\n                st.insert(j);\n            }\n        }\n        vector<int>ashu;\n        for(auto i : st)\n        {\n            ashu.push_back(i);\n        }\n        unordered_map<int,vector<int>>mp;\n        for(int i = 0 ; i < n ; i++)\n        {\n            for(int j = 0; j < m ; j++)\n            {\n                mp[grid[i][j]].push_back(i);\n            }\n        }\n        int k = ashu.size();\n        vector<vector<int>>dp(k+1 , vector<int>(1<<11 , -1));\n        return solve(0 , ashu.size() , ashu , mp , 0 , dp);\n    }\n};\n```
['Dynamic Programming', 'Ordered Map', 'Bitmask', 'C++']