728x90

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

 

1182번: 부분수열의 합

첫째 줄에 정수의 개수를 나타내는 N과 정수 S가 주어진다. (1 ≤ N ≤ 20, |S| ≤ 1,000,000) 둘째 줄에 N개의 정수가 빈 칸을 사이에 두고 주어진다. 주어지는 정수의 절댓값은 100,000을 넘지 않는다.

www.acmicpc.net

 


    from itertools import combinations
    import sys
    input = sys.stdin.readline
    n, s = map(int, input().split())
    array = list(map(int, input().split()))

    answer =0
    for i in range(1, n+1):
        coms = combinations(array, i)
        for com in coms:
            if sum(com)==s:
                answer+=1
    print(answer)
728x90

'Algorithm > 백준' 카테고리의 다른 글

[백준] 10872 팩토리얼  (0) 2023.08.08
[백준] 1927 최소 힙  (0) 2023.07.11
[백준] 1715 카드 정렬하기  (0) 2023.07.11
[백준] 11279 최대 힙  (0) 2023.07.11
[백준] 9375 패션왕 신해빈  (0) 2023.07.11

+ Recent posts