문제 링크: https://www.acmicpc.net/problem/1182
백준 알고리즘 기초 2/2 540에서 2번째 - 1182번 부분수열의 합을 풀어보았다.
풀이:
파이썬은 combinations를 썼다.
C++
Python
from itertools import combinations
n,s=map(int,input().split())
inp=list(map(int,input().split()))
cnt=0
for i in range(1,n+1):
a=combinations(inp,i)
for b in a:
if sum(b)==s:
cnt+=1
print(cnt)
Java
'코테용 문제풀이 > 백준' 카테고리의 다른 글
ABCDE 풀이 (0) | 2023.02.02 |
---|---|
종이 조각 풀이 (0) | 2023.02.02 |
집합 풀이 (0) | 2023.02.02 |
맞춰봐 풀이 (0) | 2023.02.02 |
부등호 풀이 (0) | 2023.01.31 |