Java - Bitmask DP - Easy to understand
\n\nclass Solution {\n    Integer[] dp;\n    int ALL;\n    int[][] students;\n    int[][] mentors;\n    public int maxCompatibilitySum(int[][] students, int[][]
\n```\nclass Solution {\n    Integer[] dp;\n    int ALL;\n    int[][] students;\n    int[][] mentors;\n    public int maxCompatibilitySum(int[][] students, int[][] mentors) {\n        final int nStudents = students.length;\n        final int nAnswers = students[0].length;\n        this.students = students;\n        this.mentors = mentors;\n\n        ALL = (1<<nStudents)-1;\n        dp = new Integer[ALL + 1];\n        return dfs(0,0, nAnswers);\n    }\n\n    int dfs(int iStudent, int assignedMentors, int nAnswers){\n        if (assignedMentors == ALL) return 0;\n        if(iStudent >= students.length) return 0;\n        if(dp[assignedMentors] != null) return dp[assignedMentors];\n        int max = 0;\n        for (int iMentor = 0; iMentor < mentors.length; iMentor++) {\n            if ((assignedMentors & (1 << iMentor)) == 0) {\n                final int curr = getScore(students[iStudent], mentors[iMentor], nAnswers);\n                final int right = dfs(iStudent + 1, assignedMentors | (1 << iMentor), nAnswers);\n                max = Math.max(max, curr + right);\n            }\n        }\n        return dp[assignedMentors] = max;\n    }\n\n    int getBits(int[] A){\n        int res = 0;\n        for (int a : A) {\n            res |= a;\n            res <<= 1;\n        }\n        res = res >> 1;\n        return res;\n    }\n\n    int getScore(int[] a, int[] b, int size){\n        return Integer.bitCount(getBits(a) ^ ~getBits(b)) -32 + size;\n    }\n}\n```
['Dynamic Programming', 'Bitmask', 'Java']