-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |