코딩테스트 대비/BOJ

[Baekjoon/Python] 15650번: N과 M (2) - 효과는 굉장했다!

bluetag_boy 2022. 3. 14. 00:08
반응형
 

15650번: N과 M (2)

한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해

www.acmicpc.net

 

알고리즘 분류

  • 백트래킹

 

 

SOLUTION

import sys
from itertools import combinations

N, M = map(int, sys.stdin.readline().split())

combi =  list(combinations([i for i in range(1,N+1)], M)) #combinations()함수 이용
for i in combi:
    print(*i) # *를 통해 unpacking