Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

main

[백준-2775번/Java] 부녀회장이 될테야 본문

Algorithm

[백준-2775번/Java] 부녀회장이 될테야

1984 2022. 11. 12. 20:03

* 다이나믹 프로그래밍 (DP)

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int[][] arr = new int[15][15];

		for (int i = 0; i < 15; i++) {
			arr[i][0] = i + 1;
		}

		for (int i = 1; i < 15; i++) {
			for (int j = 0; j < 15; j++) {
				if (j == 0) {
					arr[j][i] = 1;
				} else if (j > 0) {
					arr[j][i] = arr[j - 1][i] + arr[j][i - 1];
				}
			}
		}
		int N = scan.nextInt();

		for (int i = 0; i < N; i++) {
			int h = scan.nextInt();
			int w = scan.nextInt() - 1;
			if (w >= 0) {
				System.out.println(arr[w][h]);
			}
		}
		
		scan.close();

	}

}
728x90

'Algorithm' 카테고리의 다른 글

[백준-2563번/Java] 색종이  (0) 2022.11.13
[백준-1004번/Java] 어린왕자  (0) 2022.11.12
[백준-2108번/Java] 통계학  (0) 2022.11.12
[백준-13458번/Java] 시험 감독  (0) 2022.11.12
[백준-10773번/Java] 제로  (0) 2022.11.12
Comments