Skip to content

Commit bd2e9f7

Browse files
committed
[Gold V] Title: 합분해, Time: 100 ms, Memory: 14388 KB -BaekjoonHub
1 parent 7c95799 commit bd2e9f7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# [Gold V] 합분해 - 2225
2+
3+
[문제 링크](https://www.acmicpc.net/problem/2225)
4+
5+
### 성능 요약
6+
7+
메모리: 14388 KB, 시간: 100 ms
8+
9+
### 분류
10+
11+
다이나믹 프로그래밍, 수학
12+
13+
### 제출 일자
14+
15+
2025년 3월 17일 13:49:47
16+
17+
### 문제 설명
18+
19+
<p>0부터 N까지의 정수 K개를 더해서 그 합이 N이 되는 경우의 수를 구하는 프로그램을 작성하시오.</p>
20+
21+
<p>덧셈의 순서가 바뀐 경우는 다른 경우로 센다(1+2와 2+1은 서로 다른 경우). 또한 한 개의 수를 여러 번 쓸 수도 있다.</p>
22+
23+
### 입력
24+
25+
<p>첫째 줄에 두 정수 N(1 ≤ N ≤ 200), K(1 ≤ K ≤ 200)가 주어진다.</p>
26+
27+
### 출력
28+
29+
<p>첫째 줄에 답을 1,000,000,000으로 나눈 나머지를 출력한다.</p>
30+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Main {
5+
6+
static int MOD = 1000000000;
7+
8+
9+
public static void main(String[] args) throws IOException {
10+
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
13+
StringTokenizer st = new StringTokenizer(br.readLine());
14+
15+
int N = Integer.parseInt(st.nextToken());
16+
17+
int K = Integer.parseInt(st.nextToken());
18+
19+
int dp[][] = new int[N+1][K+1];
20+
21+
// 초기화 0개로 만들수 있는것의 개수는 0개, 1개로 만들수 있는 개수는 N, 1개 뿐이다.
22+
for(int i=0;i<=N;i++){
23+
dp[i][0] = 0;
24+
dp[i][1] = 1;
25+
}
26+
27+
// N이 1일 경우 만들수 있는 갯수는 K개
28+
for(int i=0;i<=K;i++){
29+
dp[1][i] = i;
30+
}
31+
32+
for(int i=2;i<=N;i++){
33+
for(int j=2;j<=K;j++){
34+
dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
35+
}
36+
}
37+
38+
System.out.println(dp[N][K]);
39+
}
40+
}
41+
42+
43+

0 commit comments

Comments
 (0)