C# DSF Solution  100%, 120ms, 25MB
public class Solution {\n    public int MaxCompatibilitySum(int[][] students, int[][] mentors) \n    {\n         int rows = students.Length;\n            int co
```public class Solution {\n    public int MaxCompatibilitySum(int[][] students, int[][] mentors) \n    {\n         int rows = students.Length;\n            int cols = students[0].Length;\n\n            int[,] compatability = new int[rows, rows];\n\n            for (int i = 0; i < rows; i++) //student\n            {\n                int[] s = students[i];\n                for (int j = 0; j < rows; j++) //mentor\n                {\n                    int[] t = mentors[j];\n\n                    int comp = 0;\n                    for (int k = 0; k < cols; k++)\n                    {\n                        if (s[k] == t[k]) comp++;\n                    }\n\n                    compatability[i, j] = comp;\n                }\n            }\n\n            int maxsum = 0;\n            return MaxCompatibilitySumDFS(compatability, 0, new bool[rows], ref maxsum, 0);\n    }\n    \n    public  int MaxCompatibilitySumDFS(int[,] compatability, int i,  bool[] visited, ref int maxsum, int sum)\n        {\n            int n = compatability.GetLength(0);\n            \n            maxsum = Math.Max(sum, maxsum);\n            if (i >= n) return maxsum;\n\n            for (int j = 0; j < n; j++)\n            {\n                if (visited[j]) continue;\n                int sum1 = sum + compatability[i, j];              \n                visited[j]=true;\n                maxsum = MaxCompatibilitySumDFS(compatability, i + 1, visited, ref maxsum, sum1);\n                visited[j] = false;\n            }\n\n            return maxsum;\n        }\n}```
[]