(C++) 1947. Maximum Compatibility Score Sum
\n\nclass Solution {\npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size(), n = 
\n```\nclass Solution {\npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size(), n = students[0].size(); \n        vector<vector<int>> score(m, vector<int>(m)); \n        for (int i = 0; i < m; ++i) \n            for (int j = 0; j < m; ++j) \n                for (int k = 0; k < n; ++k) \n                    if (students[i][k] == mentors[j][k]) ++score[i][j]; \n        \n        vector<int> dp(1 << m); \n        for (int mask = 0; mask < (1 << m); ++mask) {\n            int i = __builtin_popcount(mask); \n            for (int j = 0; j < m; ++j) \n                if (!(mask & (1 << j))) \n                    dp[mask^(1 << j)] = max(dp[mask^(1 << j)], dp[mask] + score[i][j]); \n        }\n        return dp.back(); \n    }\n};\n```
['C']