- 크기가 양수인 부분수열 즉, 원소의 개수가 최소 1개 이상인 모든 부분수열을
combination
을 이용해서 찾은 다음 합이 S가 되는지 판단해 만족하는 부분수열의 개수를 출력하는 코드를 작성했다.
from itertools import combinations
import sys
input = sys.stdin.readline
N, S = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
cnt = 0
for i in range(1, N+1):
for j in combinations(arr, i):
if sum(j) == S:
cnt += 1
print(cnt)