C++ with comments #bitmask #DP #easy
\n    int dp[9][265];\n\t// function to calculate value for some matrix a of students and other matrix b of mentors  --- \n\t\t\t\t\t// a == students[i]   && b 
```\n    int dp[9][265];\n\t// function to calculate value for some matrix a of students and other matrix b of mentors  --- \n\t\t\t\t\t// a == students[i]   && b ==  mentors[j] \n    int ch(vector<int> a, vector<int> b){\n        int n=a.size(),ans=0;\n        for(int i=0;i<n;i++){\n            if(a[i]==b[i])\n                ans++;\n        }\n        return ans;\n    }\n    int fun(vector<vector<int>>& students, vector<vector<int>>& mentors,int j,int mask){\n        int n=mentors.size();\n        if(j<0)\n            return 0;\n\t\t\t// normal dp condition \n        if(dp[j][mask]!=-1)\n            return dp[j][mask];\n\t\t\t// we will traverse for element and check the score for each students[i] and mentors[j] \n\t\t\t// and choose if and only if i is not taken already which is represented by the mask\n        for(int i=0;i<n;i++){\n\t\t// this is checking condition to check if i was already taken or not.   \n\t\t// eg. is mask was 6 then its binary representation is 110 and we want to check if i==2 is present or not \n\t\t// i.e is there 1 at the 2nd index from right. hence we take & of 110 and 100(1<< i )\n            if(mask&(1<<i)){\n                dp[j][mask]=max(dp[j][mask],ch(students[i],mentors[j])+fun(students,mentors,j-1,mask^(1<<i)));\n\t\t\t\t//  because we are now using the i th array of students we have to mark its index in the mask as 0 --- \n\t\t\t\t// mask^(1<<i) converts the index at i position to 0 \n            }\n        }\n        return dp[j][mask];\n    }\npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int n=mentors.size();\n        memset(dp,-1,sizeof dp);\n\t\t// initially all the indices (i.e n indices) of mask should be set to 1 hence the -1\n        int mask=pow(2,n)-1;\n        return fun(students,mentors,n-1,mask);\n    }\n```
['Dynamic Programming', 'Bitmask']