BOJ 11051 이항 계수2 [Java]

AMUD·2022년 4월 18일
0

Algorithm

목록 보기
18/78
post-thumbnail

문제

접근방법

구현

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

class Main {

    public static void main(String[] args) throws Exception {
        // for coding
        // System.setIn(new FileInputStream("./input/input_11051.txt"));
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ", false);

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        int[][] dp = new int[N + 1][N + 1];
        
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j <= i; j++) {
                if (i == j || j == 0) {
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % 10007;
                }
            }
        }

        bw.write(dp[N][K] + "");

        bw.close();
    }
}

제출

profile
210's Velog :: Ambition Makes Us Diligent

0개의 댓글