IT/알고리즘
백준2775번 부녀회장이될테야
어센트
2020. 1. 10. 16:12
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
|
import java.util.Scanner;
public class 부녀회장이될테야 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int T = sc.nextInt();
int k = 0, n = 0;
int res = 1;
for(int i=0;i<T;i++) {
k = sc.nextInt();
n = sc.nextInt();
int [][] arr = new int[k+1][n+1];
for(int j=1;j<k+1;j++) {
arr[j][1] = 1;
}
for(int m=1;m<n+1;m++)
arr[0][m]=m; //0층 설정
for(int j=1;j<k+1;j++) {
for(int m=1;m<n+1;m++) {
arr[j][m] = arr[j-1][m] + arr[j][m-1];
}
}
System.out.println(arr[k][n]);
}
}
}
|
cs |
생각보다 오래걸렸다. 다음부터 이런문제를 보면 바로 한자리 남기고 할당해줘야겠다.