DP+Bitmasking easy recursive solution
\n\n# Approach\nDP + Bitmasking\n\n\n\n# Code\ncpp []\nclass Solution {\n\npublic:\n\n    int dp[1025][101];\n    int solve(int ix,int mask,int n,vector<int> &t
\n\n# Approach\nDP + Bitmasking\n\n\n\n# Code\n```cpp []\nclass Solution {\n\npublic:\n\n    int dp[1025][101];\n    int solve(int ix,int mask,int n,vector<int> &temp,vector<int> arr[]){\n        if(ix==n){\n            return 0;\n        }\n        if(dp[mask][ix]!=-1) return dp[mask][ix];\n        int ans=0;\n        for(auto it:arr[temp[ix]]){\n            if((mask&(1<<it))==0){\n                cout<<it<<\' \'<<temp[ix]<<endl;\n                ans=max(ans,temp[ix]+solve(ix+1,mask|(1<<it),n,temp,arr));\n            }\n        }\n        ans=max(ans,solve(ix+1,mask,n,temp,arr));\n        return dp[mask][ix]=ans;\n    }\n    int maxScore(vector<vector<int>>& grid) {\n        unordered_set<int> s;\n        memset(dp,-1,sizeof(dp));\n        vector<int> arr[101];\n        for(int i=0;i<grid.size();i++){\n            for(int j=0;j<grid[0].size();j++){\n                s.insert(grid[i][j]);\n                arr[grid[i][j]].push_back(i);\n                \n            }\n        }\n        vector<int> temp;\n        for(auto it:s){\n            temp.push_back(it);\n        }\n        sort(temp.begin(),temp.end());\n        reverse(temp.begin(),temp.end());\n\n        \n\n        return solve(0,0,temp.size(),temp,arr);\n    }\n};\n```
['C++']