Backtracking with STL | 10 lines of code | C++
As constraints 1 <= m, n <= 8  are very small, we can easily get our answer by evaluating all possible combinations. \nTo generate all possible combinations of 
As constraints ```1 <= m, n <= 8```  are very small, we can easily get our answer by evaluating all possible combinations. \nTo generate all possible combinations of students and mentors, we can shuffle any one of them in all possible way.\n\nIn below code i m trying to shuffle students, but shuffling of vector can be costly so I have shuffled their index and evaluated their responses by using shuffled index.\n\n**C++ code:**\n```\nint maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n\tint ans = 0;\n\tvector<int> pos;\n\tfor(int i=0;i<students.size();i++) pos.push_back(i);\n\tdo{\n\t\tint curr = 0;\n\t\tfor(int i = 0;i<students.size(); i++)\n\t\t\tfor(int j=0;j<students[pos[i]].size();j++)\n\t\t\t\tcurr += (students[pos[i]][j] == mentors[i][j]);\n\t\tans = max(ans, curr);\n\t} while(next_permutation(pos.begin(), pos.end()) );\n\treturn ans;\n}\n```
[]