coding_test/BAEKJOON
백준 11050번 C언어 풀이
CodeJin
2021. 8. 27. 20:18
https://www.acmicpc.net/problem/11050
11050번: 이항 계수 1
첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))
www.acmicpc.net
조합을 구하는 문제. 이항계수가 뭔지 까먹은 나 자신 반성하자...
#include <stdio.h>
int fac (int n) {
int res = 1;
while (n > 1) {
res *= n--;
}
return res;
}
int combination (int n, int r) {
return fac(n) / (fac(r) * fac(n-r));
}
int main () {
int n, r;
scanf("%d %d", &n, &r);
printf("%d", combination(n, r));
return 0;
}