From 34a6a43627435d281515d946f744d2878dd41405 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Tue, 25 Nov 2025 23:57:25 +0900 Subject: [PATCH] =?UTF-8?q?[20251125]=20BOJ=20/=20G3=20/=20=EC=83=89?= =?UTF-8?q?=EC=83=81=ED=99=98=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3 \354\203\211\354\203\201\355\231\230.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "Seol-JY/202511/25 BOJ G3 \354\203\211\354\203\201\355\231\230.md" diff --git "a/Seol-JY/202511/25 BOJ G3 \354\203\211\354\203\201\355\231\230.md" "b/Seol-JY/202511/25 BOJ G3 \354\203\211\354\203\201\355\231\230.md" new file mode 100644 index 00000000..e4df526c --- /dev/null +++ "b/Seol-JY/202511/25 BOJ G3 \354\203\211\354\203\201\355\231\230.md" @@ -0,0 +1,53 @@ +```java +import java.util.*; + +public class Main { + static final int MOD = 1000000003; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + int K = sc.nextInt(); + + if (K * 2 > N) { + System.out.println(0); + return; + } + + if (K == 1) { + System.out.println(N); + return; + } + + long case1 = solve(N - 3, K - 1); + long case2 = solve(N - 1, K); + + long answer = (case1 + case2) % MOD; + System.out.println(answer); + } + + static long solve(int n, int k) { + if (n < 0 || k < 0) return 0; + if (k == 0) return 1; + if (n < k) return 0; + if (k * 2 - 1 > n) return 0; + + long[][] dp = new long[n + 1][k + 1]; + + dp[0][0] = 1; + if (n >= 1) { + dp[1][0] = 1; + dp[1][1] = 1; + } + + for (int i = 2; i <= n; i++) { + dp[i][0] = 1; + for (int j = 1; j <= Math.min(i, k); j++) { + dp[i][j] = (dp[i - 1][j] + dp[i - 2][j - 1]) % MOD; + } + } + + return dp[n][k]; + } +} +```