Permutations | Backtracking | C++
\nclass Solution {\n    void dfs(int i, int n, int m, vector<vector<int>>& students, vector<vector<int>>& mentors, int &ans) {\n        if(i == n) {\n          
```\nclass Solution {\n    void dfs(int i, int n, int m, vector<vector<int>>& students, vector<vector<int>>& mentors, int &ans) {\n        if(i == n) {\n            int cnt = 0;\n            for(int j=0; j<n; j++) {\n                for(int k=0; k<m; k++) cnt += students[j][k] == mentors[j][k];\n            }\n            ans = max(ans, cnt);\n            return;\n        }\n        for(int j=i; j<n; j++) {\n            swap(students[i],students[j]);\n            dfs(i + 1, n, m, students, mentors, ans);\n            swap(students[i],students[j]);\n        }\n    }\npublic:\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int n = students.size(), m = students[0].size(), ans = 0;\n        dfs(0, n, m, students, mentors, ans);\n        return ans;\n    }\n};\n```
['Backtracking', 'C++']