Skip to content

Commit db387e2

Browse files
authored
[20250928] BOJ / G5 / 알약 / 이준희
1 parent 5c6013d commit db387e2

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static long[][] dp = new long[31][31];
8+
9+
public static void main(String[] args) throws IOException {
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringBuilder sb = new StringBuilder();
12+
13+
while (true) {
14+
int n = Integer.parseInt(br.readLine());
15+
if (n == 0) {
16+
break;
17+
}
18+
sb.append(countPills(n, 0)).append("\n");
19+
}
20+
System.out.print(sb);
21+
}
22+
23+
static long countPills(int w, int h) {
24+
if (dp[w][h] != 0) {
25+
return dp[w][h];
26+
}
27+
28+
if (w == 0) {
29+
return 1;
30+
}
31+
32+
long result = countPills(w - 1, h + 1);
33+
34+
if (h > 0) {
35+
result += countPills(w, h - 1);
36+
}
37+
38+
dp[w][h] = result;
39+
return result;
40+
}
41+
}
42+
```

0 commit comments

Comments
 (0)