코딩테스트 대비/BOJ
[Baekjoon/Python] 15652번: N과 M (4) - 효과는 굉장했다!
bluetag_boy
2022. 3. 14. 00:10
반응형
15652번: N과 M (4)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
알고리즘 분류
- 백트래킹
SOLUTION
import sys
from itertools import combinations_with_replacement
N, M = map(int, sys.stdin.readline().split())
# combinations_with_replacement(iterable, r) : r길이 튜플들, 정렬된 순서, 반복되는 요소 있음
combi_replace = list(combinations_with_replacement([i for i in range(1,N+1)], M))
for i in combi_replace:
print(*i) # *를 이용해 unpacking