From c2abc1ebc6e6828763effe4e4f66724a322cce95 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 19 Feb 2026 21:04:28 +0900 Subject: [PATCH] =?UTF-8?q?[20260219]=20BOJ=20/=20G4=20/=20=EB=AF=B8?= =?UTF-8?q?=EC=B9=9C=20=EB=A1=9C=EB=B4=87=20/=20=EC=9D=B4=EC=A4=80?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\354\271\234 \353\241\234\353\264\207.md" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "JHLEE325/202602/19 BOJ G4 \353\257\270\354\271\234 \353\241\234\353\264\207.md" diff --git "a/JHLEE325/202602/19 BOJ G4 \353\257\270\354\271\234 \353\241\234\353\264\207.md" "b/JHLEE325/202602/19 BOJ G4 \353\257\270\354\271\234 \353\241\234\353\264\207.md" new file mode 100644 index 00000000..c6913252 --- /dev/null +++ "b/JHLEE325/202602/19 BOJ G4 \353\257\270\354\271\234 \353\241\234\353\264\207.md" @@ -0,0 +1,49 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static double[] probs = new double[4]; + static boolean[][] visited = new boolean[30][30]; + static int[] dr = {0, 0, 1, -1}; + static int[] dc = {1, -1, 0, 0}; + static double totalProb = 0; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + for (int i = 0; i < 4; i++) { + probs[i] = Integer.parseInt(st.nextToken()) * 0.01; + } + + visited[15][15] = true; + dfs(15, 15, 0, 1.0); + + System.out.println(totalProb); + } + + static void dfs(int r, int c, int cnt, double currentProb) { + if (cnt == N) { + totalProb += currentProb; + return; + } + + for (int i = 0; i < 4; i++) { + if (probs[i] == 0) continue; + + int nr = r + dr[i]; + int nc = c + dc[i]; + + if (!visited[nr][nc]) { + visited[nr][nc] = true; + dfs(nr, nc, cnt + 1, currentProb * probs[i]); + visited[nr][nc] = false; + } + } + } +} +```