(백준) 15666 – 엔앤엠(12) (Python)

쉬운 목차

문제

15666: N과 M (12) (acmicpc.net)

15666호: N과 M (12)

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

www.acmicpc.net

설명

Combinations_with_replacement와 set 함수를 함께 사용했습니다.

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

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
new_A = sorted(set(combinations_with_replacement(A, M)))

for i in new_A :
    print(*i)