반응형
2407번: 조합
n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)
www.acmicpc.net

코드
import math
n,m = map(int,input().split())
top = math.factorial(n)
bottom = math.factorial(m)*math.factorial(n-m)
print(top//bottom)
설명
이항 계수를 구하는 공식은 다음과 같다.

팩토리얼 계산은 math 라이브러리에서 제공하는 factorial 함수를 이용하여 구했다.
반응형
'알고리즘 > dynamic programming' 카테고리의 다른 글
| [백준][Python] 1890번 점프 (0) | 2022.05.17 |
|---|---|
| [백준][Python] 1912번 연속합 (0) | 2022.05.16 |
| [백준][Python] 11727번 2×n 타일링 2 (0) | 2022.05.12 |
| [백준][Python] 11726번 2×n 타일링 (0) | 2022.05.11 |
| [백준][Python] 1463번 1로 만들기 (0) | 2022.05.10 |
댓글