본문 바로가기
Algorithm(BOJ, Python)/Mathematics

[백준_1010] 다리놓기 python

by kurooru 2022. 7. 12.

dp로 풀어도 되는 문제지만,

조합이라는 수학적 지식이 조금만 있다면

훨씬 편하게 풀 수 있는 문제였다.

# math 라이브러리 사용
import math

# t 입력
t = int(input())
for _ in range(t):
    
    # n, m 입력
    n, m = map(int, input().split())

    # output = 조합의 수
    output = math.factorial(m) // (math.factorial(n) * math.factorial(m-n))

    # 출력
    print(output)

 

'Algorithm(BOJ, Python) > Mathematics' 카테고리의 다른 글

[백준_13239] Combinations python  (0) 2022.07.31
[백준_9655] 돌게임 python  (0) 2022.07.16
[백준_11051] 이항 계수 2 python  (0) 2022.07.12
[백준_10407] 2타워 python  (0) 2022.06.13