DP + bitmask
```\n/\n\n1010 matrix\n\n\nfrom ecah row we will select atmost one no.\n\n\nso we will keep track of no. selected from each row, so that we will not select the 
```\n/*\n\n10*10 matrix\n\n\nfrom ecah row we will select atmost one no.\n\n\nso we will keep track of no. selected from each row, so that we will not select the same no. in upcoming row\n\nobviously we will select atmost 10 no\'s\n\n\nas grid[i][j]<=100, we can\'t use bitmask to keep track of selected no\'s\n\n\nREVERSE THE bimask LOGIC (STANDARD) :-\n\ninstead of storing selected no. in bitmask, we store the row from which we have already done the selection\n\nbut how we will ensure unique no. is selected ?\n\nsuppsoe current mask => m1\n\ncurrently I am selecting no= x (starting from 100) from some row, making that row set in the mask, and in next recusrion call i will select (x-1) from some other row\n\n\nwe will store rows of each no. in map (int => vector<int>)\n\n\n*/\n\n\nint dp[101][1<<11];\n\n\nint n,m;\n\nunordered_map<int, vector<int>>mp;\n\n\nclass Solution {\npublic:\n   \n\n    int maxScore(vector<vector<int>>& grid) {\n       \n        mp.clear();\n        \n        memset(dp,-1,sizeof(dp));\n        \n        n=grid.size();\n        \n        m=grid[0].size();\n        \n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                mp[grid[i][j]].push_back(i);\n            }\n        }\n        \n        return find(100, 0, grid);\n        \n    }\n    \n    int find(int no, int mask, vector<vector<int>>&grid){\n       \n        if(no==0)\n            return 0;\n        \n        if(dp[no][mask]!=-1)\n            return dp[no][mask];\n        \n        \n        // not selecting this no. from any row or no. not present in the grid\n        \n        int ans= find(no-1, mask, grid);\n        \n        \n        for(int row: mp[no]){\n            if(mask & (1<<row))\n                continue;\n            \n            ans=max(ans, no+ find(no-1, mask|(1<<row), grid));\n        }\n        \n        \n        return dp[no][mask]=ans;\n    }\n\n};\n
['Bitmask']