본문 바로가기

Programming [Python]/백준 알고리즘 솔루션

#117 백준 파이썬 [15652] N과 M (4) - 중복 조합

https://www.acmicpc.net/problem/15652

 

#Solution

https://claude-u.tistory.com/161 참고. 중복 조합 메써드인 combinations_with_replacement로 바꾸어서 푼다. 수학적으로는 nHr이다.

import itertools

N, M = map(int, input().split())
num_list = [i for i in range(1, N+1)]
    
for num in itertools.combinations_with_replacement(num_list, M):
    for i in num:
        print(i, end = ' ')
    print(end = '\n')