Skip to content

Commit ced8455

Browse files
committed
[Combination] baekjoon-1010
1 parent bb09b76 commit ced8455

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@
7070
| # || Problem | Note |
7171
| :-: | :----: | :------------------------------------------------------------------------------------------------------------------ | :------------------------ |
7272
| 01 | | [Baekjoon-11050 이항 계수 1](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/Combination/P11050) | |
73-
| 02 | | [Baekjoon-11051 이항 계수 2](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/Combination/P11051) | DP |
73+
| 02 | | [Baekjoon-11051 이항 계수 2](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/Combination/P11051) | DP |
74+
| 03 | | [Baekjoon-1010 다리 놓기](https://github.com/Seogeurim/Algorithm-practice/blob/master/src/Combination/P1010) | |

src/Combination/P1010/Main.java

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package Combination.P1010;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.InputStreamReader;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.StringTokenizer;
9+
10+
public class Main {
11+
12+
static int T, N, M;
13+
static int combis[][];
14+
15+
public static void main(String[] args) throws Exception{
16+
System.setIn(new FileInputStream("src/Combination/P1010/input.txt"));
17+
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
StringTokenizer st;
20+
21+
T = Integer.parseInt(br.readLine());
22+
for (int t = 0; t < T; t++) {
23+
st = new StringTokenizer(br.readLine());
24+
N = Integer.parseInt(st.nextToken());
25+
M = Integer.parseInt(st.nextToken());
26+
27+
combis = new int[M+1][N+1];
28+
for (int i = 1; i <= M; i++) {
29+
for (int j = 0; j <= N; j++) {
30+
if (j == 0 || i == j)
31+
combis[i][j] = 1;
32+
else combis[i][j] = (combis[i-1][j-1] + combis[i-1][j]);
33+
}
34+
}
35+
36+
System.out.println(combis[M][N]);
37+
}
38+
}
39+
}

src/Combination/P1010/input.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
3
2+
2 2
3+
1 5
4+
13 29

0 commit comments

Comments
 (0)