dp+bitmask => 100%fast c++
\tclass Solution {\n\tpublic:\n\t\tint dp[15][5000],m;\n    \n    int sol(vector&stud,vector&ment,int i,int mask){\n        //cout<<"here\n";\n        if(i>=siz
\tclass Solution {\n\tpublic:\n\t\tint dp[15][5000],m;\n    \n    int sol(vector<int>&stud,vector<int>&ment,int i,int mask){\n        //cout<<"here\\n";\n        if(i>=size(stud))\n            return 0;\n        \n        if(dp[i][mask]!=-1)\n            return dp[i][mask];\n        \n        int ans=0,score;\n        for (int j=0;j<size(ment);++j) {\n            if ((mask>>j)&1) \n                continue;\n            score = m-__builtin_popcount(stud[i]^ment[j]);\n            //cout<<score<<" "<<m<<\'\\n\';\n            ans=max(ans,score+sol(stud,ment,i+1,mask|(1<<j)));\n        }\n        return dp[i][mask]=ans;\n    }\n        \n    \n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        m = size(students[0]);\n        \n        memset(dp,-1,sizeof dp);\n        vector<int>stud,ment;\n        int x;\n    \n        for (int i=0;i<size(students);++i){\n            //cout<<"here\\n";\n            x=0;\n            for (int b:students[i]){\n                x+=b;\n                x<<=1;\n            }\n            x>>=1;\n            stud.push_back(x);\n            x=0;\n            for (int b:mentors[i]){\n                x+=b;\n                x<<=1;\n            }\n            x>>=1;\n            ment.push_back(x);\n        }\n        \n        \n        return sol(stud,ment,0,0);\n    }\n\t};
[]