From ea4083c4ab74b250e69f6d0fd0dd5343f1b5b86b Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Thu, 26 Feb 2026 23:54:38 +0900 Subject: [PATCH] =?UTF-8?q?[20260226]=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?=EA=B9=80=EB=AF=BC=EC=A7=84?= 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" | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 "zinnnn37/202602/26 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" diff --git "a/zinnnn37/202602/26 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" "b/zinnnn37/202602/26 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..ed73fc02 --- /dev/null +++ "b/zinnnn37/202602/26 BOJ G3 \354\206\214\353\254\270\353\202\234 \354\271\240\352\263\265\354\243\274.md" @@ -0,0 +1,87 @@ +```java +import java.io.*; + +public class BJ_1941_소문난_칠공주 { + + private static final int N = 5; + private static final int SIZE = 25; + private static final int[] dx = { -1, 1, 0, 0 }; + private static final int[] dy = { 0, 0, -1, 1 }; + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int ans; + private static boolean[] visited; + private static boolean[][] isS; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + isS = new boolean[N][N]; + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < N; j++) { + isS[i][j] = line.charAt(j) == 'S'; + } + } + visited = new boolean[1 << SIZE]; + } + + private static void sol() throws IOException { + for (int i = 0; i < SIZE; i++) { + if (!isS[i / N][i % N]) continue; + + int mask = 1 << i; + + visited[mask] = true; + dfs(1, 1, mask); + } + + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static void dfs(int depth, int sCount, int mask) { + if (7 - depth + sCount < 4) return; + + if (depth == 7) { + ans++; + return; + } + + for (int i = 0; i < SIZE; i++) { + if ((mask & (1 << i)) == 0) continue; + + int x = i / N; + int y = i % N; + + for (int d = 0; d < 4; d++) { + int nx = x + dx[d]; + int ny = y + dy[d]; + + if (OOB(nx, ny)) continue; + + int next = nx * N + ny; + int nextMask = mask | (1 << next); + + if ((mask & (1 << next)) != 0) continue; + if (visited[nextMask]) continue; + + visited[nextMask] = true; + dfs(depth + 1, sCount + (isS[nx][ny] ? 1 : 0), nextMask); + } + } + } + + private static boolean OOB(int x, int y) { + return x < 0 || N <= x || y < 0 || N <= y; + } + +} +``` \ No newline at end of file