정답 코드
#1182번: 부분수열의 합
import sys
def find(pointer, total):
global answer
if pointer >= n:
return
find(pointer + 1, total) # 토탈에 현재 값이 반영되지 않음
total += a[pointer]
find(pointer + 1, total) # 토탈에 현재 값 반영
if total == s:
answer += 1
n, s = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
answer = 0
find(0, 0)
print(answer)
'알고리즘 > 백준' 카테고리의 다른 글
[백준 알고리즘] 1759번: 암호 만들기 (Python / 파이썬) (2) | 2024.01.25 |
---|---|
[백준 알고리즘] 6603번: 로또 (Python / 파이썬) (0) | 2024.01.24 |
[백준 알고리즘] 15649번: N과 M(1) (Python / 파이썬) (0) | 2024.01.24 |
[백준 알고리즘] 7569번: 토마토 (Python / 파이썬) (0) | 2024.01.22 |
[백준 알고리즘] 2206번: 벽 부수고 이동하기 (Python / 파이썬) (4) | 2024.01.22 |