From a4cff52b2ee677a42f3871731e0bf2b021af2893 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Mon, 16 Feb 2026 22:26:42 +0900 Subject: [PATCH] =?UTF-8?q?[20260216]=20BOJ=20/=20G3=20/=20=EC=86=8C?= =?UTF-8?q?=EB=AC=B8=EB=82=9C=20=EC=B9=A0=EA=B3=B5=EC=A3=BC=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\271\240\352\263\265\354\243\274.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "JHLEE325/202602/16 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" diff --git "a/JHLEE325/202602/16 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" "b/JHLEE325/202602/16 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" new file mode 100644 index 00000000..c43b2d60 --- /dev/null +++ "b/JHLEE325/202602/16 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" @@ -0,0 +1,70 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static char[][] map = new char[5][5]; + static int[] selected = new int[7]; + static int ans = 0; + static int[] dr = {-1, 1, 0, 0}; + static int[] dc = {0, 0, -1, 1}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + for (int i = 0; i < 5; i++) { + map[i] = br.readLine().toCharArray(); + } + + combination(0, 0, 0); + System.out.println(ans); + } + + static void combination(int idx, int cnt, int sCnt) { + if (cnt - sCnt > 3) return; + + if (cnt == 7) { + if (sCnt >= 4) { + if (isConnected()) ans++; + } + return; + } + + if (idx == 25) return; + + selected[cnt] = idx; + combination(idx + 1, cnt + 1, sCnt + (map[idx / 5][idx % 5] == 'S' ? 1 : 0)); + + combination(idx + 1, cnt, sCnt); + } + + static boolean isConnected() { + boolean[] visited = new boolean[7]; + Deque q = new ArrayDeque<>(); + + q.add(0); + visited[0] = true; + int count = 1; + + while (!q.isEmpty()) { + int curIdx = q.poll(); + int r = selected[curIdx] / 5; + int c = selected[curIdx] % 5; + + for (int i = 0; i < 4; i++) { + int nr = r + dr[i]; + int nc = c + dc[i]; + + for (int next = 0; next < 7; next++) { + if (!visited[next] && selected[next] / 5 == nr && selected[next] % 5 == nc) { + visited[next] = true; + count++; + q.add(next); + } + } + } + } + return count == 7; + } +} +```