[Python] 백준 - 15650번: N과 M (2)

Jisoo Ha·2024년 5월 31일

coding-test 공부

목록 보기
15/15

문제 링크 -> https://www.acmicpc.net/problem/15650

접근

  • 백준 15649번과 유사하게 풀되, 중복 수열만 제거해 주면 된다.

코드

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
arr = []

def bt(x):
    if len(arr) == m:
        print(*arr)
        return
    for i in range(x, n+1):
        if i not in arr:
            arr.append(i)
            bt(i)
            arr.pop()

bt(1)

추가

[Python] 백준 - 15649번: N과 M (1)
https://velog.io/@cmlh21/Python-%EB%B0%B1-15649%EB%B2%88-N%EA%B3%BC-M-1

profile
우주 먼지

0개의 댓글