기록/알고리즘
백준 1775번) 부녀회장이 될 테야
3.
2020. 6. 24. 21:34
SMALL
문제 설명에서는 (i, j)호에 입주하기 위해서 (i, 0), (i, 1), ... (i, j -1)호의 주민 수를 모두 더해야한다.
하지만 직접 그려보면 (i, j)호의 주민 수는 (i, j - 1) + (i - 1, j)의 값과 같다.
전체 크기가 주어졌으므로, 전체를 계산 후 필요한 값만 출력하면 된다.
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String args[]) throws IOException {
Scanner scan = new Scanner(System.in);
//input case
int testcase = scan.nextInt();
int[][] result = new int[testcase][2];
for(int i = 0; i < testcase; i++) {
result[i][0] = scan.nextInt();
result[i][1] = scan.nextInt();
}
int[][] apart = new int[15][15];
for(int i = 1; i < 15; i++) {
apart[0][i] = i;
}
apart[0][0] = 1;
for(int i = 1; i < 15; i++) {
for(int j = 1; j < 15; j++) {
apart[i][j] = apart[i - 1][j] + apart[i][j - 1];
}
}
for(int i = 0; i < testcase; i++) {
System.out.println(apart[result[i][0]][result[i][1]]);
}
}
}
SMALL