최종코드(코드링크)
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(중복 순열) 문법을 안다면 간단히 풀 수 있는 문제였습니다 :)
'알고리즘 문제 풀이' 카테고리의 다른 글
[백준 - Python] 6603. 로또 (0) | 2024.08.13 |
---|---|
[백준 - Python] 15657. N과 M (8) (0) | 2024.08.12 |
[백준 - Python] 15655. N과 M (6) (0) | 2024.08.12 |
[백준 - Python] 15654. N과 M (5) (0) | 2024.08.12 |
[프로그래머스 - Python] 비밀지도 (0) | 2024.08.09 |