From d544c3a52467666df70f6aca1c0525b0af1f873d Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 4 Sep 2025 22:11:24 +0900 Subject: [PATCH] =?UTF-8?q?[20250904]=20BOJ=20/=20P5=20/=20=EC=A7=95?= =?UTF-8?q?=EA=B2=80=EB=8B=A4=EB=A6=AC=20=EB=92=A4=EB=A1=9C=20=EA=B1=B4?= =?UTF-8?q?=EB=84=88=EA=B8=B0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\261\264\353\204\210\352\270\260.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" diff --git "a/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" "b/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" new file mode 100644 index 00000000..2287703d --- /dev/null +++ "b/khj20006/202509/04 BOJ P5 \354\247\225\352\262\200\353\213\244\353\246\254 \353\222\244\353\241\234 \352\261\264\353\204\210\352\270\260.md" @@ -0,0 +1,90 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static final long MOD = (long)1e9 + 7; + + static int N, K; + static long[][] dp; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + N = io.nextInt(); + K = io.nextInt(); + if(N <= 2) { + io.write("1\n"); + return; + } + + dp = new long[N+1][K+1]; + for(int i=3;i<=N;i++) for(int x=1;x<=K && i-x>0;x++) { + if(i-x <= 2) dp[i][x] = (dp[i][x] + 1) % MOD; + else for(int y=1;y<=K && i-x-y>0;y++) { + if(i-x-y <= 2) dp[i][x] = (dp[i][x] + (i-x+1-Math.max(i-x-y+1,i-K))) % MOD; + else dp[i][x] = (dp[i][x] + dp[i-x][y] * (i-x+1-Math.max(i-x-y+1,i-K))) % MOD; + } + } + + long ans = 0; + for(int x=1;x<=K && N-x>0;x++) ans = (ans + dp[N][x]) % MOD; + io.write(ans + "\n"); + + io.close(); + + } + +} +```