From 6a9fafdfaebfe149d8dc6e3273479147a91107c5 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Sun, 29 Jun 2025 15:04:23 +0900 Subject: [PATCH] =?UTF-8?q?[20250629]=20BOJ=20/=20G4=20/=20=EB=AC=BC?= =?UTF-8?q?=ED=86=B5=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../29 BOJ G4 \353\254\274\355\206\265" | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "suyeun84/202506/29 BOJ G4 \353\254\274\355\206\265" diff --git "a/suyeun84/202506/29 BOJ G4 \353\254\274\355\206\265" "b/suyeun84/202506/29 BOJ G4 \353\254\274\355\206\265" new file mode 100644 index 00000000..abbcc750 --- /dev/null +++ "b/suyeun84/202506/29 BOJ G4 \353\254\274\355\206\265" @@ -0,0 +1,52 @@ +```java +import java.io.*; +import java.util.*; + +public class boj2251 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static int A, B, C; + static Set answer; + static boolean[][][] visited; + static int[] capacity; + public static void main(String[] args) throws Exception { + nextLine(); + A = nextInt(); + B = nextInt(); + C = nextInt(); + answer = new TreeSet<>(); + capacity = new int[]{A, B, C}; + visited = new boolean[A + 1][B + 1][C + 1]; + + dfs(0, 0, C); + + for (int a : answer) System.out.print(a + " "); + } + static void dfs(int a, int b, int c) { + if (visited[a][b][c]) return; + + visited[a][b][c] = true; + + if (a == 0) answer.add(c); + + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (i != j) { + int[] next = pour(new int[]{a, b, c}, i, j); + dfs(next[0], next[1], next[2]); + } + } + } + } + static int[] pour(int[] state, int from, int to) { + int[] next = state.clone(); + int amount = Math.min(state[from], capacity[to] - state[to]); + next[from] -= amount; + next[to] += amount; + return next; + } +} +```