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차원 배열 조합 로직과 동일!
'개발 이론 > 알고리즘' 카테고리의 다른 글
[Algorithm] 이분 탐색 (Binary Search) (1) | 2024.04.26 |
---|---|
[Algorithm] 다익스트라(Dijkstra) 알고리즘 (1) | 2024.03.07 |
[Algorithm] 플로이드-워셜(Floyd-Warshall) 알고리즘 (0) | 2024.03.05 |
[Algorithm] 투 포인터 (Two pointers) 알고리즘 (0) | 2023.06.02 |
[Algorithm] 2차원 배열 빈 공간 채우기 | 위에서 아래로 내리기 (0) | 2022.04.06 |