Skip to content

Commit 76fccc7

Browse files
authored
Merge pull request #968 from AlgorithmWithGod/lkhyun
[20250924] BOJ / G4 / 함께 블록 쌓기 / 이강현
2 parents e8915e5 + 2f6d910 commit 76fccc7

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static StringBuilder sb = new StringBuilder();
10+
static int N,M,H;
11+
static List<Integer>[] blocks;
12+
13+
public static void main(String[] args) throws Exception {
14+
st = new StringTokenizer(br.readLine());
15+
N = Integer.parseInt(st.nextToken());
16+
M = Integer.parseInt(st.nextToken());
17+
H = Integer.parseInt(st.nextToken());
18+
19+
blocks = new List[N+1];
20+
for (int i = 1; i <= N; i++) {
21+
blocks[i] = new ArrayList<>(M+1);
22+
}
23+
24+
for (int i = 1; i <= N; i++) {
25+
st = new StringTokenizer(br.readLine());
26+
while(st.hasMoreTokens()){
27+
blocks[i].add(Integer.parseInt(st.nextToken()));
28+
}
29+
blocks[i].add(0); //블록 안 쌓는 경우 고려
30+
}
31+
32+
int[][] dp = new int[N+1][H+1];//dp[i][j] = i번째 학생까지 고려했을때, j 높이를 쌓는 경우의 수
33+
dp[0][0] = 1;
34+
35+
for (int i = 1; i <= N; i++) {
36+
for (int j = 0; j <= H; j++) {
37+
for (int cur : blocks[i]) {
38+
if(cur <= j){
39+
dp[i][j] += dp[i-1][j-cur];
40+
dp[i][j] %= 10007;
41+
}
42+
}
43+
}
44+
}
45+
bw.write(dp[N][H] + "");
46+
bw.close();
47+
}
48+
49+
}
50+
```

0 commit comments

Comments
 (0)