[Python3] permutations
Approach 1 - brute force\n\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        m = len(stu
**Approach 1 - brute force**\n```\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        m = len(students)\n        \n        score = [[0]*m for _ in range(m)]\n        for i in range(m): \n            for j in range(m): \n                score[i][j] = sum(x == y for x, y in zip(students[i], mentors[j]))\n        \n        ans = 0 \n        for perm in permutations(range(m)): \n            ans = max(ans, sum(score[i][j] for i, j in zip(perm, range(m))))\n        return ans \n```\n\nEdited on 7/26/2021\n**Approach 2 - dp**\n```\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        m = len(students)\n        \n        score = [[0]*m for _ in range(m)]\n        for i in range(m): \n            for j in range(m): \n                score[i][j] = sum(x == y for x, y in zip(students[i], mentors[j]))\n        \n        @cache \n        def fn(mask, j): \n            """Return max score of assigning students in mask to first j mentors."""\n            ans = 0 \n            for i in range(m): \n                if not mask & (1<<i): \n                    ans = max(ans, fn(mask^(1<<i), j-1) + score[i][j])\n            return ans \n        \n        return fn(1<<m, m-1)\n```
['Python3']