Skip to content

Instantly share code, notes, and snippets.

@raven38
Created October 15, 2014 11:11
Show Gist options
  • Save raven38/2ba0450d142a7eafe590 to your computer and use it in GitHub Desktop.
Save raven38/2ba0450d142a7eafe590 to your computer and use it in GitHub Desktop.
組み合わせの総数を求める。 combination
#define MOD 100000007
long long comb(int P_, int Q_){
static const int N_ = 1020;
static long long C_[N_][N_];
if(C_[0][0]==0){
int i,j;
for(i = 0; i < N_; ++i) C_[i][0] = C_[i][i] = 1;
for(i = 0; i < N_; ++i) for(j = 1; j < i; ++j) C_[i][j] = (C_[i-1][j-1] + C_[i-1][j])%MOD;
}
return C_[P_][Q_];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment