본문 바로가기

알고리즘 문제풀이

백준 1010 다리 놓기 Python 조합 실버5

재귀 함수를 이용해서 팩토리얼을 만들고 이것을 가지고 조합식에 적용해서 풀이

def fact(n):
    if n>1:
        return n * fact(n-1)
    else:
        return 1

t = int(input())
for tc in range(t):
    n, m = map(int,input().split())
    result = fact(m) // (fact(m-n) * fact(n))
    print(result)