Skip to content

Commit

Permalink
2024-07-12
Browse files Browse the repository at this point in the history
  • Loading branch information
mjj111 committed Jul 30, 2024
1 parent 16d0313 commit 39532be
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mjj111/μ΄ν•­κ³„μˆ˜2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class μ΄ν•­κ³„μˆ˜2 {
public static final int MOD = 10007;
private static int[][] dp;

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());
dp = new int[N + 1][K + 1];

System.out.println(binomialCoefficient(N, K));
}

static private int binomialCoefficient(int n, int k) {

if (dp[n][k] > 0) {
return dp[n][k];
}

if (k == 0 || n == k) {
return dp[n][k] = 1;
}

// nCk = (n-1)C(k-1) + (n-1)C(k)
return dp[n][k] = (binomialCoefficient(n - 1, k - 1)
+ binomialCoefficient(n - 1, k)) % MOD;
}
}

0 comments on commit 39532be

Please sign in to comment.