[python] Simple solution using itertools.permutations()
Since this was originally a contest problem, we want to find a solution that\'s simple to code.\n\nFirst thing to do is look at the constraints and when we do w
Since this was originally a contest problem, we want to find a solution that\'s simple to code.\n\nFirst thing to do is look at the constraints and when we do we notice that both m and n are at most 8. When the constraints are this small (less than 10/11) this means we can likely use a factorial time solution (or a polynomial solution with a high power.)\n\nAnd 8! is only 40k, so we can just try all pairings of mentor and student, since there are 8! of them.\n\n```\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        ans = 0\n        for perm in itertools.permutations(range(len(students))):\n            cur = 0\n            for i in range(len(students)):\n                for j in range(len(students[0])):\n                    cur += 1 if students[i][j] == mentors[perm[i]][j] else 0\n            ans = max(ans, cur)\n        return ans\n```\n\nThis uses `O(m! * n * m)` time and the extra memory use is `O(m)`.\n\n### Bonus One-Line version\nGranted it\'s split over multiple lines for readabilty.\n\nThe one trick I use is that `sum(array_of_bools)` returns the number of `True`s in the array.\n\n```\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        return max(\n            sum(\n                students[i][j] == mentors[perm[i]][j]\n                for i in range(len(students)) \n                for j in range(len(students[0]))\n            ) \n            for perm in itertools.permutations(range(len(students)))\n        )\n```
['Python']