DP + bitmask | skip element or take it while maintaining masking of row id
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    unordered_map<int,vector<int>>mp;\n    vector<vector<int>>dp;\n    vector<int>v;\n    int ans=0;\n    int help(int i,int mask,int n)\n    {\n        if(i>=n)return 0;\n        if(dp[i][mask]!=-1)return dp[i][mask];\n        int ans=0;\n        for(auto row:mp[v[i]])\n        {\n            if((mask & (1 << row))==0)\n            {\n                ans=max(ans,v[i]+help(i+1,(mask|(1<<row)),n));\n            }\n        }\n        return dp[i][mask]=max(ans,help(i+1,mask,n));\n    }\n    int maxScore(vector<vector<int>>& grid) {\n        set<int>st;\n        for(int i=0;i<grid.size();i++)\n        {\n            for(int j=0;j<grid[0].size();j++)\n            {\n                st.insert(grid[i][j]);\n            }\n        }\n        for(auto t:st)v.push_back(t);\n        sort(v.begin(),v.end(),greater<int>());\n        for(int i=0;i<grid.size();i++)\n        {\n            for(int j=0;j<grid[0].size();j++)\n            {\n                mp[grid[i][j]].push_back(i);\n            }\n        }\n        dp.resize(v.size()+1,vector<int>(2000,-1));\n        return help(0,0,v.size());\n    }\n};\n```
['C++']