![[백준 / BOJ] 11050번 이항 계수 1 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FNSGdV%2FbtrJreUxBhF%2FjZwDq8P3WgJi65Vf8xSKM1%2Fimg.png)
[백준 / BOJ] 11050번 이항 계수 1 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 6. 10. 20:23
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/11050
11050번: 이항 계수 1
첫째 줄에 \(N\)과 \(K\)가 주어진다. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))
www.acmicpc.net
문제

문제 풀이
이항 계수는 팩토리얼로 풀어쓸 수 있고, 이는 아래와 같으므로 그대로 구현하면 된다.
파이썬은 math 함수를 사용했다.

C++ 코드 전문
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
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
int Factorial(int N) { | |
if (N <= 1) | |
return 1; | |
else | |
return N * Factorial(N - 1); | |
} | |
void init() { | |
std::ios_base::sync_with_stdio(false); | |
std::cin.tie(nullptr); | |
std::cout.tie(nullptr); | |
} | |
int main() { | |
init(); | |
int N, K; | |
std::cin >> N >> K; | |
std::cout << Factorial(N) / (Factorial(K) * Factorial(N - K)); | |
return 0; | |
} |
Python 코드 전문
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
import sys | |
import math | |
input = sys.stdin.readline | |
N, K = map(int, input().split()) | |
print(math.comb(N, K)) |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 1010번 다리 놓기 (C++, Python) (0) | 2022.06.12 |
---|---|
[백준 / BOJ] 11051번 이항 계수 2 (C++, Python) (0) | 2022.06.10 |
[백준 / BOJ] 3036번 링 (C++, Python) (0) | 2022.06.09 |
[백준 / BOJ] 2981번 검문 (C++, Python) (0) | 2022.06.09 |
[백준 / BOJ] 1934번 최소공배수 (C++, Python) (0) | 2022.06.07 |
@Reo :: 코드 아카이브
자기계발 블로그