Skip to content

Commit ed0b742

Browse files
authored
Merge pull request #530 from AlgorithmWithGod/lkhyun
[20250723] BOJ / G4 / 배수 공사 / 이강현
2 parents b57b5ad + a04a9d5 commit ed0b742

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 int N,X;
10+
static int[] pipeLen;
11+
static int[] pipeCnt;
12+
static int[] dp; // dp[i] = 길이 i를 만드는 방법의 수
13+
14+
public static void main(String[] args) throws Exception {
15+
st = new StringTokenizer(br.readLine());
16+
N = Integer.parseInt(st.nextToken());
17+
X = Integer.parseInt(st.nextToken());
18+
19+
pipeLen = new int[N];
20+
pipeCnt = new int[N];
21+
dp = new int[X+1];
22+
23+
for (int i = 0; i < N; i++) {
24+
st = new StringTokenizer(br.readLine());
25+
pipeLen[i] = Integer.parseInt(st.nextToken());
26+
pipeCnt[i] = Integer.parseInt(st.nextToken());
27+
}
28+
29+
dp[0] = 1;
30+
for (int i = 0; i < N; i++) { //모든 파이프에 대하여
31+
for (int j = X; j >= 0; j--) { //길이를 고려
32+
for (int k = 1; k <= pipeCnt[i]; k++) {
33+
if(j - pipeLen[i]*k >= 0){
34+
dp[j] += dp[j-pipeLen[i]*k];
35+
}
36+
}
37+
}
38+
}
39+
bw.write(dp[X]+"");
40+
bw.close();
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)