본문 바로가기

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

#258 백준 파이썬 [15666] N과 M (12) - 중복 조합

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

 

Python Code

from itertools import combinations_with_replacement #중복 조합

N, M = map(int, input().split())
N_list = list(map(int, input().split()))
N_list = sorted(N_list) #순서대로 나오게 정렬 먼저
output = []

for numbers in list(combinations_with_replacement(N_list, M)):
    if not output:
        output.append(numbers)
    elif numbers not in output:
        output.append(numbers)
            
for numbers in output:
    for num in numbers:
        print(num, end=' ')
    print()