Easy C++  Solution || Bitmask + DP || 100% Faster ✔✔
\n\n# Code\n\nclass Solution {\npublic:\n    int dp[8][256];\n    int calcSum(vector<int> &v1,vector<int> &v2){\n        int cnt=0;\n        for(int i=0;i<v1.si
\n\n# Code\n```\nclass Solution {\npublic:\n    int dp[8][256];\n    int calcSum(vector<int> &v1,vector<int> &v2){\n        int cnt=0;\n        for(int i=0;i<v1.size();i++) cnt+=(v1[i]==v2[i]);\n        return cnt;\n    }\n    int help(int idx,int mask, vector<vector<int>>& students, vector<vector<int>>& mentors,int m){\n        if(idx==m) return 0;\n        if(dp[idx][mask]!=-1) return dp[idx][mask];\n        int sum=0;\n        for(int  i=0;i<m;i++){\n            if(mask&(1<<i)){\n                sum=max(sum,calcSum(students[idx],mentors[i])+help(idx+1,mask^(1<<i),students,mentors,m));\n            }\n        }\n        return dp[idx][mask]=sum;\n    }\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m=students.size();\n        memset(dp,-1,sizeof dp);\n        return help(0,(1<<m)-1,students,mentors,m);\n    }\n};\n```
['Dynamic Programming', 'Bitmask', 'C++']