[C++] DP + Bitmask | 15 lines of code with explanation | 0ms | Beats 100%
We assign j-th mentor to i-th student from the set of mentors available.  We iterate with a fixed mentors available. For every mentor_set, if we calculate the c
We assign j-th mentor to i-th student from the set of mentors available.  We iterate with a fixed mentors available. For every mentor_set, if we calculate the compatibility score of assigning j-th mentor to i-th student then what is important for us is the compatibility score of assigning all other mentors (exept j-th) from current mentor-set to all other students (exept i-th). Also, if we have k mentors available then k students only can be used since exactly one mentor must be assigned to each student. Hence, finally our answer is when all (m) mentors are considered in mentor-set.\n\n```\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size(), n = students[0].size();\n        vector<int> dp((1 << m), 0);\n        for (int mentor_set = 0; mentor_set < (1 << m); ++mentor_set) {\n            int i = __builtin_popcount(mentor_set) - 1;\n            for (int j = 0; j < m; ++j) {\n                if (mentor_set & (1 << j)) {\n                    int curr = 0;\n                    for (int k = 0; k < n; ++k)\n                        if (students[i][k] == mentors[j][k])\n                            ++curr;\n                    dp[mentor_set] = max(dp[mentor_set], curr + dp[mentor_set & ~(1 << j)]);\n                }\n            }\n        }\n        return dp[(1 << m) - 1];\n    }\n  \n  ```
[]