Python Bitmask Memoization Solution
\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        n = len(students)\n        m = len(st
```\nclass Solution:\n    def maxCompatibilitySum(self, students: List[List[int]], mentors: List[List[int]]) -> int:\n        n = len(students)\n        m = len(students[0])\n        full = 1<<n\n        dp = [[-1 for i in range(full)] for j in range(n)]\n        def rec(mentorMask, studentIndex):\n            if mentorMask==full-1 or studentIndex==n:\n                return 0\n            if dp[studentIndex][mentorMask]!=-1:\n                return dp[studentIndex][mentorMask]\n            ans = 0\n            for j in range(n):\n                if mentorMask&(1<<j)==0:\n                    score = 0\n                    for i in range(m):\n                        if students[studentIndex][i]==mentors[j][i]:\n                            score+=1                   \n                    ans = max(ans, score + rec(mentorMask^(1<<j), studentIndex+1))\n            dp[studentIndex][mentorMask] = ans\n            return ans\n        return rec(0,0)\n```
[]