Created
April 2, 2020 09:25
-
-
Save Astro36/a045545380c3d4be321d394a2f791ca4 to your computer and use it in GitHub Desktop.
https://gall.dcinside.com/m/github/7529 Solution(C++17)
This file contains hidden or 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
#include <iostream> | |
template<unsigned int N> | |
constexpr unsigned int factorial_v = N * factorial_v<N - 1>; | |
template<> | |
constexpr unsigned int factorial_v<1> = 1; | |
template<unsigned int N, unsigned int K> | |
constexpr unsigned int binomial_v = factorial_v<N> / (factorial_v<K> * factorial_v<N - K>); | |
template<unsigned int... Ks> | |
constexpr unsigned int multinomial_v = factorial_v<(Ks + ...)> / (factorial_v<Ks> * ...); | |
int main() { | |
std::cout << factorial_v<5> << std::endl; // 120 | |
std::cout << binomial_v<5, 2> << std::endl; // 10 | |
std::cout << multinomial_v<5> << std::endl; // 1 | |
std::cout << multinomial_v<3, 2> << std::endl; // 10 | |
std::cout << multinomial_v<2, 2, 2> << std::endl; // 90 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment