알고리즘/알고리즘(초급)

백트래킹을 이용한 부분 집합을 구하는 알고리즘

상상2 2022. 11. 21. 07:57
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a_list = list(map(int,input().split()))

total_result = []
result = []
def BT(depth):

    if depth == n:
        total_result.append(result.copy())
        return

    result.append(a_list[depth])
    BT(depth+1)
    result.pop()
    BT(depth+1)

BT(0)

print(total_result)