C++ | DP | BITMASKING | Beats 95%
\nclass Solution {\npublic:\n    int dp[8][1<<8];\n    int ans = 0;\n    int dfs(vector<vector<int>>& students, vector<vector<int>>&mentors, int idx, int mask){
```\nclass Solution {\npublic:\n    int dp[8][1<<8];\n    int ans = 0;\n    int dfs(vector<vector<int>>& students, vector<vector<int>>&mentors, int idx, int mask){\n        if(idx == students.size()) return 0;\n        if(dp[idx][mask]!=-1)return dp[idx][mask]; \n        int ans = 0;\n        for(int i = 0; i < mentors.size(); i++){\n            if(mask&(1<<i)) continue;\n            int marks = 0;\n            for(int j = 0; j < students[0].size(); j++){\n                if(students[idx][j]==mentors[i][j])marks++;\n            }\n            ans=max(ans,marks + dfs(students, mentors, idx+1, mask|1<<i));\n        }\n        return dp[idx][mask]=ans;\n    }\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        memset(dp,-1,sizeof(dp));\n        return dfs(students, mentors, 0, 0);\n    }\n};\n```
['Dynamic Programming', 'C', 'Bitmask']