Skip to content

Instantly share code, notes, and snippets.

@aakashns
Created June 13, 2012 18:07
Show Gist options
  • Save aakashns/2925573 to your computer and use it in GitHub Desktop.
Save aakashns/2925573 to your computer and use it in GitHub Desktop.
Dynamic programming algorithm for calculating binomial coefficients
#define C_MAX 250
int C[C_MAX][C_MAX];
C[0][0] = 1;
for (int i = 1; i < C_MAX; i++){
C[i][0] = 1;
for (int j = 1; j <= i; j++){
/* Actual Binomial Coefficient */
//C[i][j] = C[i-1][j] + C[i-1][j-1];
/* Binomial Coefficient modulo MAX */
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MAX;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment