[백준] 11050번 이항 계수 1 / C++
#문제
#풀이
#include <iostream>
using namespace std;
int factorial(const int x)
{
int input = x;
int value = 1;
while (input > 0)
{
value *= input--;
}
return value;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int N, K;
cin >> N >> K;
int ans = factorial(N) / (factorial(K) * factorial(N - K));
cout << ans;
return 0;
}
#정리
조합론에서 매우 중요한 개념인 이항 계수. 다음 식을 코드로 작성하여 해결함. \(\binom{n}{k} = \frac{n!}{k!(n-k)!}\)
Enjoy Reading This Article?
Here are some more articles you might like to read next: