-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1010.java
More file actions
41 lines (29 loc) · 1018 Bytes
/
boj1010.java
File metadata and controls
41 lines (29 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class boj1010 {
static int[][] dp = new int[30][30];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for (int i = 0; i < T; i++) {
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
sb.append(comb(M, N)).append('\n');
}
System.out.println(sb);
}
static int comb(int n, int m) {
if (dp[n][m] > 0) {
return dp[n][m];
}
if (n == m || m == 0) {
return dp[n][m] = 1;
}
return dp[n][m] = comb(n - 1, m - 1) + comb(n - 1, m);
}
}