-문제:https://www.acmicpc.net/problem/1010

 

-정답풀이:

서쪽에서 n개 만큼을 선택한 후 순서대로(겹치지 않게) 동쪽과 연결해주면 된다. 따라서 조합을 이용하면 된다 

 

주의할 점

나눌 때 '/'로 하면 몫이 답.0으로 소수로 출력되고, '//'로 하면 답은 정수로 출력된다. 

 

from itertools import combinations는 특정 리스트에서 n개를 조합할 때 사용하고, 

특정 조합의 수를 구하려면 math의 factorial와 조합의 공식(n!/(n-r)!r!)을 이용해서 답을 구해야한다 

import math
t=int(input())

for _ in range(t):
    n,m=map(int,input().split())
    answer= math.factorial(m)//(math.factorial(m-n)* math.factorial(n))
    print(answer)

+ Recent posts