Recursion Solution
Intuition\nInitially, I considered a greedy approach for solving the problem, where I would always chreoose the maximum compatibility score. However, I realized
# Intuition\nInitially, I considered a greedy approach for solving the problem, where I would always chreoose the maximum compatibility score. However, I realized that this approach may not yield the correct result. Instead, I decided to adopt a recursive approach to solve the problem.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThe code finds the maximum compatibility sum between students and mentors by exploring all possible pairings using a recursive approach. It calculates compatibility scores for each pairing and tracks visited mentors to ensure each student gets paired only once. The maximum score is returned as the result. \n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(N^2 * M)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N^2)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int f(vector<vector<pair<int, int>>> &pq, int index, vector<int>& visited) {\n        if (index == pq.size()) {\n            return 0;\n        }\n        int score = 0;\n        for (int i = 0; i < pq[index].size(); i++) {\n            if (visited[i] != 1) {\n                visited[i] = 1;\n                score = max(score, pq[index][i].second + f(pq, index + 1, visited));\n                visited[i] = 0; \n            }\n        }\n        return score;\n    }\n\n    int maxCompatibilitySum(vector<vector<int>>& students, vector<vector<int>>& mentors) {\n        int n = students.size();\n        int m = students[0].size();\n        vector<vector<pair<int, int>>> pq(n);\n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                int score = 0;\n                for (int k = 0; k < m; k++) {\n                    if (students[i][k] == mentors[j][k]) {\n                        score++;\n                    }\n                }\n                pq[i].push_back({j, score});\n            }\n        }\n        vector<int> visited(n, 0);\n        return f(pq, 0, visited);\n    }\n};\n\n```
['Recursion', 'C++']