CodingTest/SW Expert Academy

[ SW Expert Academy ] 2817. 부분수열의 합

EEOOOO 2022. 11. 16. 17:23

1차 제출. PASS

전체 후보군 구해서(라이브러리 사용) 조건에 맞는 경우의 수 합산했다.

from itertools import combinations

T = int(input())
for tc in range(1, T+1):
    n, k = map(int, input().split())
    nums = list(map(int, input().split()))
    result = 0
    for i in range(1, n+1):
        comb = combinations(nums, i)
        for c in comb:
            if sum(list(c)) == k:
                result += 1
    print("#{} {}".format(tc, result))