본문 바로가기
알고리즘/dynamic programming

[백준][Python] 2407번 조합

by 임짠짠 2022. 5. 13.
반응형
 

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 함수를 이용하여 구했다.

반응형

댓글