프로그래밍/백준
백준 1010 다리 놓기 - 파이썬
터렛짓는다
2021. 7. 13. 14:01
문제.
풀이.
우선 이 문제는 조합을 구하는 방식으로 풀 수 있다
M개 중에 N개를 골라야하므로 MCN 으로 풀 수 있다
조합의 식은 (M!) / (N!)*((M-N)!) 이다.
소스코드.
import sys
from math import factorial
tc = int(sys.stdin.readline())
for i in range(tc):
N, M = map(int, sys.stdin.readline().split())
result = factorial(M) // (factorial(N) * factorial(M-N))
print(result)