Skip to content

Commit

Permalink
递推法计算组合数
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-XYS authored Nov 27, 2016
1 parent fcdbb41 commit 4a61aad
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Combination(Recursion).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <cstdio>

#define MOD 1000000000
#define MAX 1000

int C[MAX][MAX];

void init_C()
{
for (int i = 0; i < MAX; i++)
{
C[i][0] = 1;
}
for (int i = 1; i < MAX; i++)
{
for (int j = 1; j <= i; j++)
{
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
}
}
}

int main()
{
int n, m;
init_C();
while (scanf("%d%d", &n, &m) > 0)
{
printf("%d\n", C[n][m]);
}
return 0;
}

0 comments on commit 4a61aad

Please sign in to comment.