Maximum Compatibility from Pairing Two Groups
You pair each member of one group with a unique partner in another group. Compatibility between a pair is the number of survey answers they share. Find the pairing that maximizes total compatibility.
Problem
Given two m x n binary matrices students and mentors, where each row is a person's answers to n yes/no questions, the compatibility score of a student-mentor pair is the number of positions where their answers match. Assign each student to a unique mentor to maximize the total compatibility. Return that maximum.
Input
Two m x n binary matrices students and mentors.
Output
An integer: the maximum total compatibility over all one-to-one pairings.
Constraints
- 1 <= m, n <= 8
- Entries are 0 or 1.
Examples
Example 1
Input
students = [[1,1,0],[1,0,1],[0,0,1]], mentors = [[1,0,0],[0,0,1],[1,1,0]]
Output
8
An optimal assignment yields total compatibility 8.
Example 2
Input
students = [[0,0],[0,0],[0,0]], mentors = [[1,1],[1,1],[1,1]]
Output
0
No answers match, so every pairing scores 0.