-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ1010.java
More file actions
51 lines (39 loc) · 1.3 KB
/
Copy pathJ1010.java
File metadata and controls
51 lines (39 loc) · 1.3 KB
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
42
43
44
45
46
47
48
49
50
51
package TIL;
import java.util.*;
import java.io.*;
public class J1010 {
static int[][] dp;
public static void main(String[] args) throws IOException{
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(buffer.readLine());
int t = 0;
while(T > t){
String[] input = buffer.readLine().split(" ");
int N = Integer.parseInt(input[0]);
int M = Integer.parseInt(input[1]);
dp = new int[M+1][M+1];
for(int i = 0; i<= M; i++) {
dp[i][1] = i;
dp[i][0] = 1;
dp[i][i] = 1;
}
// for(int i = 1 ; i <= M; i++){
// for(int j = 1 ; j <= M; j++){
// dp[i][j] = dp[i-1][j]+dp[i-1][j-1];
// }
// }
t++;
System.out.println(combo(M,N));
for(int i = 0 ; i <= M; i++){
for(int j = 0 ; j <= M; j++){
System.out.print(dp[i][j]+ " ");
}
System.out.println();
}
}
}
public static int combo(int M, int N){
if (dp[M][N] != 0) return dp[M][N];
return dp[M][N] = combo(M-1,N) + combo(M-1,N-1);
}
}