(백준) 15652 – N과 M (4) (Python)

쉬운 목차

문제

#15652: N과 M (4) (acmicpc.net)

15652호: N과 M (4)

문제의 조건을 만족하는 일련의 숫자를 한 줄에 하나씩 인쇄합니다. 중복 시퀀스는 한 번 이상 인쇄해서는 안 되며 각 시퀀스는 공백으로 구분하여 인쇄해야 합니다. 시퀀스는 알파벳 오름차순으로 인쇄됩니다.

www.acmicpc.net

설명

조합은 중복을 허용하므로 Combinations_with_replacement가 사용됩니다.

from sys import stdin
from itertools import combinations_with_replacement
input = lambda : stdin.readline().strip()

N, M = map(int, input().split())
A = sorted(combinations_with_replacement((i for i in range(1, N + 1)), M))

for i in A :
    print(*i)