[C++] Backtracking Solution
\nclass Solution {\n    // Calculating compatibility scores of ith student and jth mentor\n    int cal(int i,int j,vector<vector<int>>& arr1,vector<vector<int>>
```\nclass Solution {\n    // Calculating compatibility scores of ith student and jth mentor\n    int cal(int i,int j,vector<vector<int>>& arr1,vector<vector<int>>& arr2){\n        int cnt=0;\n        for(int k=0;k<arr1[0].size();k++){\n            if(arr1[i][k]==arr2[j][k]){\n                cnt++;\n            }\n        }\n        return cnt;\n    }\n    \n    int helper(int i,int m,vector<vector<int>>& arr1,vector<vector<int>>& arr2,vector<bool>& vis){\n        if(i==m){\n            return 0;\n        }\n        int ans = 0;\n        for(int j=0;j<m;j++){\n            if(!vis[j]){\n                vis[j]=1;\n                ans = max(ans,cal(i,j,arr1,arr2) + helper(i+1,m,arr1,arr2,vis));\n                vis[j]=0; // Backtracking\n            }\n        }\n        return ans;\n    }\n    \npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int m = students.size();\n        vector<bool> vis(m,0); // To keep track of which mentor is already paired up\n        return helper(0,m,students,mentors,vis);\n    }\n};\n```\n**Hit upvote if you like :)**
['Backtracking', 'C']