[백준 완전탐색] 부분수열의 합(python)

이진규·2022년 2월 13일
1

백준(PYTHON)

목록 보기
43/115

문제

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

나의 코드

"""
1. 아이디어
모든 경우(1개의 부분집합을 뽑는 경우 ~ n개의 부분집합을 뽑는 경우)에 대해서
조합 라이브러리를 이용해서 리스트로 뽑아낸다음 리스트의 합이 s와 같은 경우를 카운트 한다.

2. 시간복잡도

"""

from itertools import combinations
from sys import stdin
input = stdin.readline

n, s = map(int, input().split())
nums = list(map(int, input().split()))
cnt = 0

for i in range(1, n+1):
    lst = list(combinations(nums, i))

    for x in lst:
        if sum(x) == s:
            cnt += 1

print(cnt)
    

느낀점

profile
항상 궁금해하고 공부하고 기록하자.

0개의 댓글