Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Created October 25, 2015 10:27
Show Gist options
  • Save bowbowbow/a5c3dec77cd3edd4d3fd to your computer and use it in GitHub Desktop.
Save bowbowbow/a5c3dec77cd3edd4d3fd to your computer and use it in GitHub Desktop.
#include <iostream>
#include <memory.h>
using namespace std;
#define MAXN 1500
int cashe[MAXN][MAXN];
int binomial(int n, int k, int p){
if(cashe[n][k] != -1 ) return cashe[n][k];
if(k ==0 || k == n)
return cashe[n][k] = 1;
return cashe[n][k] = (binomial(n-1, k-1, p)+binomial(n-1, k, p))%p;
}
int main(){
memset(cashe, -1, sizeof(cashe));
int N, K;
cin >> N >> K;
cout << binomial(N, K, 7) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment