본문 바로가기
알고리즘 & 자료구조/백준

백준 2775

by 신재권 2021. 7. 28.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main2775 {

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(bf.readLine());
		int[][] apt = new int[15][15];
		
		for(int i=0; i<15; i++){
			apt[i][1] = 1;
			apt[0][i] = i;
		}
		
		for(int i=1; i<15; i++){
			for(int j=2; j<15; j++){
				apt[i][j] = apt[i][j-1] + apt[i-1][j]; // -1호 + 아래층 호의 합 
			}
		}
		
		for(int i=0; i<T; i++){
			int k = Integer.parseInt(bf.readLine());
			int n = Integer.parseInt(bf.readLine());
			System.out.println(apt[k][n]);
		}
	}	

}

각층의 조건은 자기 옆호 (-1호)  + 자기 바로 아래층 호의 사람수 합 을 구하면 풀 수 있다.

'알고리즘 & 자료구조 > 백준' 카테고리의 다른 글

백준 10828  (0) 2021.08.04
백준 2839  (0) 2021.08.03
백준 2750  (0) 2021.07.28
백준 10250  (0) 2021.07.22
백준 2869  (0) 2021.07.21