[C++] Backtracking Solution, faster than 100%
The idea is simple :-\n1) I made a 2D matrix of size MM for every possible combination.\n2) then find "Maximum sum of a Matrix where each value is from a unique
The idea is simple :-\n1) I made a 2D matrix of size M*M for every possible combination.\n2) then find "Maximum sum of a Matrix where each value is from a unique row and column".\n\n```\nclass Solution {\npublic:\n    vector<int> col;\n    int mx = INT32_MIN;\n    void maxSum(int n, vector<vector<int>> &matrix, int idx, int sum)\n    {\n        if (idx == n)\n        {\n            mx = max(mx, sum);\n            return;\n        }\n        for (int i = 0; i < n; i++)\n        {\n            if (!col[i])\n            {\n                col[i] = true;\n                maxSum(n, matrix, idx + 1, sum + matrix[idx][i]);\n                col[i] = false;\n            }\n        }\n    }\n    void fillMatrix(vector<int>&s,vector<int>&m, int i, int j, vector<vector<int>>&matrix)\n    {\n        int x = 0;\n        for(int k = 0; k<s.size(); k++)\n        {\n            if(s[k]==m[k])\n                x++;\n        }\n        matrix[i][j] = x;\n    }\n    \n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size();\n        vector<vector<int>>matrix(m,vector<int>(m,0));\n        for(int i = 0; i<m; i++)\n        {\n            for(int j = 0; j<m; j++)\n            {\n                fillMatrix(students[i],mentors[j], i, j, matrix);\n            }\n        }\n        col.assign(m, false);\n        maxSum(m, matrix, 0, 0);\n        return mx;\n    }\n};\n```\n\n\n**Upvote if you like!!!**
['Backtracking', 'C']