백준 2775번 자바 : 부녀회장이 될테야

Rena·2022년 3월 6일
0

알고리즘 문제풀이

목록 보기
4/45
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] apt = new int[15][15];

		for(int i=0; i<apt.length; 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];
			}
		}

		int t = sc.nextInt();
		
		for(int s=0;s<t;s++) {
			int k = sc.nextInt();
			int n = sc.nextInt();
			System.out.println(apt[k][n]);
		}
		sc.close();
	}
}

2차원 배열을 활용한다
직접 노트에 그리면 이해가 빠른 문제

profile
일을 사랑하고 싶은 개발자

0개의 댓글