코딩테스트 대비/BOJ
[Baekjoon/Python] 15666번: N과 M (12) - 효과는 굉장했다!
bluetag_boy
2022. 3. 28. 02:18
반응형
15666번: N과 M (12)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
알고리즘 분류
- 백트래킹
SOLUTION
import sys
from itertools import combinations_with_replacement
N, M = map(int, sys.stdin.readline().split())
N_list = list(map(int, sys.stdin.readline().split()))
N_list.sort()
# 중복되는 수열 출력을 방지하기 위해 set() 이용
combi_w_list = sorted(set(list(combinations_with_replacement(N_list, M))))
for i in combi_w_list:
print(*i)