알고리즘/백준 문제풀이

[boj] 백준 15655 N과 M (7) python 풀이

감자156 2023. 8. 8. 11:05
반응형

문제

https://www.acmicpc.net/problem/15656

 

문제 풀이

백트래킹

 

코드

import sys
input = sys.stdin.readline

N, M = map(int,input().split())
List = sorted(list(map(int,input().split())))

total = []
def back():
    if len(total) == M:
        print(*total)
        return 

    for i in List:
        total.append(i)
        back()
        total.pop()
       
back()
반응형