From e0c56cc2b071c892548209adf9458fb4f96d2bf8 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Thu, 7 Aug 2025 23:34:49 +0900 Subject: [PATCH] =?UTF-8?q?[20250807]=20BOJ=20/=20G4=20/=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20=EB=B8=94=EB=A1=9D=20=EC=8C=93=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\241\235 \354\214\223\352\270\260.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "LiiNi-coder/202508/08 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" diff --git "a/LiiNi-coder/202508/08 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" "b/LiiNi-coder/202508/08 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" new file mode 100644 index 00000000..3d554999 --- /dev/null +++ "b/LiiNi-coder/202508/08 BOJ \355\225\250\352\273\230 \353\270\224\353\241\235 \354\214\223\352\270\260.md" @@ -0,0 +1,58 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.StringTokenizer; + +public class Main { + private static int N; + private static int M; + private static int H; + private static int[][] blocks; + private static int[][] dp; + private static final int MOD = 10007; + 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()); + M = Integer.parseInt(st.nextToken()); + H = Integer.parseInt(st.nextToken()); + + blocks = new int[N][]; + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + int[] temp = new int[st.countTokens()]; + for (int j = 0; j < temp.length; j++) { + temp[j] = Integer.parseInt(st.nextToken()); + } + blocks[i] = temp; + } + + dp = new int[N + 1][H + 1]; + for (int i = 0; i <= N; i++) { + for (int j = 0; j <= H; j++) { + dp[i][j] = -1; + } + } + System.out.println(dfs(0, 0)); + } + + private static int dfs(int i, int h) { + if (h > H) return 0; + if (i == N) return h == H ? 1 : 0; + if (dp[i][h] != -1) return dp[i][h]; + int result = dfs(i + 1, h); + for (int b : blocks[i]) { + if (h + b <= H) { + result += dfs(i + 1, h + b); + //맨 마지막에 나누지말고 미리 빼버리기 + if (result >= MOD) + result -= MOD; + } + } + dp[i][h] = result; + return result; + } +} +```