Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10-mjj111 #209

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading