Skip to content

Instantly share code, notes, and snippets.

@recoverlee
Created October 15, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recoverlee/83e92c26b8fbf3d61788 to your computer and use it in GitHub Desktop.
Save recoverlee/83e92c26b8fbf3d61788 to your computer and use it in GitHub Desktop.
combination
// nPr = n! / (n-r)!
// nCr = nPr / r! = n! / ((n-r)! * r!)
int combination(int n, int r)
{
int ret = 1;
for (int i = 1; i <= r; i++)
{
ret = ret*(n - i + 1) / i;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment