int[][] walls = new int[N][N];

static void pickLocation (int cnt, int start) {
        if (cnt == 3) {
            for (int[] wall : walls) {
                if (map[wall[0]][wall[1]] != 0) return;
            }
            max = Math.max(max, spread());
        } else {
            for (int i = start; i < N * M; i++) {
                int x = i / M;
                int y = i % M;

                walls[cnt] = new int[]{x, y};
                pickLocation(cnt + 1, i + 1);
            }
        }
    }

2차원 배열 선언

x 값은 i / M, y 값은 i % M. walls[cnt] = new int[] {x, y} 로 생성. 나머지는 1차원 배열 조합 로직과 동일!