-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1182.cpp
More file actions
35 lines (31 loc) · 750 Bytes
/
1182.cpp
File metadata and controls
35 lines (31 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
using namespace std;
int N, S, answer=0, numbers[21];
void dfs(int sum, int idx){
sum += numbers[idx];
if(idx >= N) return;
if(sum == S) answer++;
dfs(sum, idx+1);
dfs(sum-numbers[idx],idx+1);
}
int main(){
cin >> N >> S;
for(int i=0;i<N;++i){
cin >> numbers[i];
}
dfs(0,0);
cout << answer;
}
// dfs를 통해 각 숫자의 합을 더해서 확인
//// Python combination을 활용
// from itertools import combinations
// N, S = map(int, (input().split()))
// numbers = list(map(int, input().split()))
// cn = []
// for i in range(1, N+1):
// cn.extend(list(combinations(numbers, i)))
// cnt = 0
// for tmp in cn:
// if sum(tmp) == S:
// cnt += 1
// print(cnt)