백준 2775번(Java)

박은지·2025년 2월 4일

백준

목록 보기
10/89
post-thumbnail

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static int[][] apt = new int[15][15];
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String result = "";
		makeApt();
		int T = Integer.parseInt(br.readLine());
		
		for(int i=0; i<T; i++) {
			int k = Integer.parseInt(br.readLine());
			int n = Integer.parseInt(br.readLine());
			
			result += apt[k][n] + "\n";
		}
		System.out.println(result);
		br.close();
	}

	public static void makeApt() {
		for(int i=0; i<15; i++) {
			apt[i][1] = 1; // i층 1호
			apt[0][i] = i; // 0층 i호
		}
		
		for(int i=1; i<15; i++) { // 1층~14층
			for(int j=2; j<15; j++) { // 2호~14호
				apt[i][j] = apt[i][j-1] + apt[i-1][j]; // i층 전호 + i-1층 같은호
			}
		}
	}
}
profile
백엔드 개발자가 되고싶은 eunzi😊

0개의 댓글