forked from b-chae/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1182.cpp
More file actions
41 lines (36 loc) · 613 Bytes
/
Copy path1182.cpp
File metadata and controls
41 lines (36 loc) · 613 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
36
37
38
39
40
41
#include <iostream>
#include <vector>
using namespace std;
int T;
vector<long> N;
long sum;
long ans = 0;
bool include[20];
void print(int idx, int selected) {
if (idx == T && selected > 0) {
long tempsum = 0;
for (int i = 0; i < T; i++) {
if (include[i]) {
tempsum += N[i];
}
}
if (tempsum == sum) ans += 1;
}
if (idx >= T) return;
include[idx] = true;
print(idx + 1, selected + 1);
include[idx] = false;
print(idx + 1, selected);
}
int main()
{
int i, tmp;
cin >> T >> sum;
for (i = 0; i < T; i++) {
cin >> tmp;
N.push_back(tmp);
}
print(0, 0);
cout << ans;
return 0;
}