Last active
April 15, 2021 09:47
-
-
Save ruan4261/deb0cfb744f77e8616d41a7021d0afa7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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