C++ Solution using Permutation
\nclass Solution {\npublic:\n    int cal(vector<vector<int>> &mentors, vector<vector<int>> &students)\n    {\n      int n=students.size(),m=students[0].size(),s
```\nclass Solution {\npublic:\n    int cal(vector<vector<int>> &mentors, vector<vector<int>> &students)\n    {\n      int n=students.size(),m=students[0].size(),sum=0;\n        \n      for(int i=0;i<n;i++)\n      {\n          for(int j=0;j<m;j++)\n          {\n              sum+=(students[i][j]==mentors[i][j])?1:0;\n          }\n      }\n        \n      return sum;\n    }\n    \n    int permutation(vector<vector<int>>&mentors, vector<vector<int>>&students, int index, int maxSum)\n    {\n        if(index==mentors.size())\n        {\n            maxSum=max(maxSum,cal(mentors,students));\n            return maxSum;\n        }\n        \n        for(int i=index;i<mentors.size();i++)\n        {\n            swap(mentors[i],mentors[index]);\n            \n            maxSum=max(maxSum,permutation(mentors,students,index+1,maxSum));\n            \n            swap(mentors[i],mentors[index]);\n        }\n        \n        return maxSum;\n    }\n    \n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int n=students.size(),maxSum=INT_MIN;\n        \n        maxSum=permutation(mentors,students,0,maxSum);\n        \n        return maxSum;\n    }\n};\n```
[]