Skip to content

Instantly share code, notes, and snippets.

@ruan4261
Last active April 15, 2021 09:47
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 ruan4261/deb0cfb744f77e8616d41a7021d0afa7 to your computer and use it in GitHub Desktop.
Save ruan4261/deb0cfb744f77e8616d41a7021d0afa7 to your computer and use it in GitHub Desktop.
// Arrangement or Permutation
int P(int n, int m) {
int res = 1;
int limit = n - m;
while (n > limit) {
res *= n--;
}
return res;
}
// Combination
int C(int n, int m) {
m = Math.min(m, n - m);
int res = P(n, m);
while (m > 0) {
res /= m--;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment