DP Solution using Bitmask
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:O(n*m*2^n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n*m*2^n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\nint maxScore(vector<vector<int>>& g) {\n    int n=g.size(),m=g[0].size();\n    vector<pair<int,int>>v;\n    for(int i=0;i<n;i++){\n        for(int j=0;j<m;j++){\n            v.push_back({g[i][j],i});\n        }\n    }\n    int N=n*m;\n    sort(v.begin(),v.end(),greater<pair<int,int>>());\n    vector<vector<int>>dp(N,vector<int>(1<<n,-1));\n\n    function<int(int,int)>find=[&](int i,int mask)->int{\n        if(i>=N)return 0;\n        if(dp[i][mask]!=-1)return dp[i][mask];\n        int ans=0;\n        if((mask&(1<<v[i].second))){\n            ans+=find(i+1,mask);\n        }\n        else{\n            int j=i;\n            while(j<N and v[i].first==v[j].first)j++;\n\n            int newMask=(mask|(1<<v[i].second));\n            ans=max(ans,v[i].first+find(j,newMask));\n            ans=max(ans,find(i+1,mask));\n        }       \n        return dp[i][mask]=ans;       \n    };\n    return find(0,0);\n\n}\n};\n```
['C++']