package leetcode;

/**
 * https://leetcode.com/problems/maximum-compatibility-score-sum/
 */
public class Problem1947 {
    public int maxCompatibilitySum(int[][] students, int[][] mentors) {
        int[] studentArray = toArray(students);
        int[] mentorArray = toArray(mentors);
        return 0;
    }

    private static int[] toArray(int[][] twoDArray) {
        int[] array = new int[twoDArray.length];
        for (int i = 0; i < twoDArray.length; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j : array) {
                sb.append(j);
            }
            array[i] = Integer.parseInt(sb.toString(), 2);
        }
        return array;
    }

    public static void main(String[] args) {
        Problem1947 prob = new Problem1947();
        System.out.println(prob.maxCompatibilitySum(new int[][]{
            {1,1,0},{1,0,1},{0,0,1}
        }, new int[][]{
            {1,0,0},{0,0,1},{1,1,0}
        })); // 8
//        System.out.println(prob.maxCompatibilitySum(new int[][]{
//            {0,0},{0,0},{0,0}
//        }, new int[][]{
//            {1,1},{1,1},{1,1}
//        })); // 0
    }
}

@@ -294,17 +294,131 @@
  return 
-0
+maxCompatibilitySum(studentArray, mentorArray, students%5B0%5D.length, 0,%0A            new boolean%5BstudentArray.length%5D)
 ;%0A    %7D%0A
@@ -651,21 +651,28 @@
 int j : 
-a
+twoDA
 rray
+%5Bi%5D
 ) %7B%0A    
@@ -818,21 +818,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -832,441 +832,698 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem1947 prob = new Problem1947();%0A        System.out.println(prob.maxCompatibilitySum(new int%5B%5D%5B%5D%7B%0A            %7B1,1,0%7D,%7B1,0,1%7D,%7B0,0,1%7D%0A        %7D, new int%5B%5D%5B%5D%7B%0A            %7B1,0,0%7D,%7B0,0,1%7D,%7B1,1,0%7D%0A        %7D)); // 8%0A//        System.out.println(prob.maxCompatibilitySum(new int%5B%5D%5B%5D%7B%0A//            %7B0,0%7D,%7B0,0%7D,%7B0,0%7D%0A//        %7D, new int%5B%5D%5B%5D%7B%0A//            %7B1,1%7D,%7B1,1%7D,%7B1,1%7D%0A//        %7D)); // 0
+int maxCompatibilitySum(int%5B%5D students, int%5B%5D mentors, int bitLength,%0A                                           int index, boolean%5B%5D visited) %7B%0A        if (index == students.length) %7B%0A            return 0;%0A        %7D%0A        int max = 0;%0A        for (int i = 0; i %3C mentors.length; i++) %7B%0A            if (visited%5Bi%5D) %7B%0A                continue;%0A            %7D%0A            visited%5Bi%5D = true;%0A            int xor = students%5Bindex%5D %5E mentors%5Bi%5D;%0A            int sum = maxCompatibilitySum(students, mentors, bitLength, index + 1, visited)%0A                + bitLength - Integer.bitCount(xor);%0A            max = Math.max(max, sum);%0A            visited%5Bi%5D = false;%0A        %7D%0A        return max;
 %0A    %7D%0A
+
 %7D
-%0A

Solve problem 1947