알고리즘 문제 풀이

[백준 - Python] 15656. N과 M (7)

김혠 2024. 8. 12. 10:47

문제링크

 

최종코드(코드링크)

import itertools

N, M = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()

comb = itertools.product(arr, repeat = M)
for i in comb:
    for j in i:
        print(j, end=" ")
    print()

N과 M (6)은 permutation(순열)이었다면 N과 M (7)은 product(중복 순열)입니다.

파이썬 product(중복 순열) 문법을 안다면 간단히 풀 수 있는 문제였습니다 :)