코딩테스트

백준 1010번

eunGI 2022. 9. 15. 19:36

n은 m보다 작거나 같기 때문에 다리를 연결할 때 m개의 사이트 중에 n개를 뽑아서 겹치지 않게 그냥 쭉쭉쭉 연결하면 됨

 

mCn 공식을 이용해서 m개의 사이트 중 n개를 뽑으면 된다.

import math


def number_of_case(x, y):
    # bCa를 구해야하니까 b!/(b-a)!a!
    # math.factorial()
    return math.factorial(y)//(math.factorial(y-x)*math.factorial(x))


count = int(input())

for _ in range(count):
    x, y = map(int, input().split())
    print(number_of_case(x, y))

 

 

함수에서

return math.factorial(y)//(math.factorial(y-x)*math.factorial(x))

해당 부분을 

return math.factorial(y)//math.factorial(y-x)*math.factorial(x)

이렇게 해서 계속 틀림

분모니까 괄호로 묶어야됨 뒤에거 두개 + /말고 //로 해야됨, 경우의 수니까 소수 안됨

'코딩테스트' 카테고리의 다른 글

백준 10989 [계수 정렬]  (0) 2022.09.22
백준 1015번  (0) 2022.09.19
백준 2751 (퀵 정렬)  (0) 2022.09.07
백준 2750번 (선택, 삽입 정렬)  (0) 2022.09.06
[이것이 코딩테스트다] 미로찾기  (0) 2022.07.12