[백준] 11050번 이항 계수 1 / C++

#문제

백준 11050번 이항 계수 1

#풀이

#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:

  • [백준] 1934번 최소공배수 / C++
  • [백준] 1940번 주몽 / C++
  • [백준] 1037번 최소공배수 / C++
  • [백준] 10773번 제로 / C++
  • [백준] 11651번 좌표 정렬하기 2 / C++