녕의 학습 기록
백준_11051 이항 계수 2 (조합) 본문
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class BJ_11051_이항계수2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int[][] d = new int[n+1][n+1];
int i;
for (i=1; i<n+1; i++) {
d[i][0] = 1;
d[i][1] = i;
d[i][i] = 1;
}
int j;
for (i=2; i<n+1; i++) {
for (j=2; j<i+1; j++) {
d[i][j] = ((d[i-1][j-1] % 10007) + (d[i-1][j] % 10007)) % 10007;
}
}
System.out.println(new StringBuilder().append(d[n][k]));
}
}
11051번: 이항 계수 2
첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 1,000, 0 ≤ \(K\) ≤ \(N\))
www.acmicpc.net
'Algorithm > Algorithm 문제' 카테고리의 다른 글
백준_1010 다리 놓기 (1) | 2024.04.01 |
---|---|
백준_2775 부녀회장이 될테야 (조합) (0) | 2024.03.28 |
백준_11050 이항 계수 1 (조합) (0) | 2024.03.24 |
백준_11438 LCA2 (빠른 최소 공통 조상) (0) | 2024.03.19 |
백준_11437 LCA (최소공통조상 일반) (0) | 2024.03.18 |