-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1208.cpp
More file actions
67 lines (58 loc) · 1.09 KB
/
Copy path1208.cpp
File metadata and controls
67 lines (58 loc) · 1.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;
vector<int> A, B;
map<int, int> cnt;
int S;
long long answer;
void dfsA(int now, int sum, int selected)
{
if (now == A.size())
{
if (selected != 0)
{
if (sum == S)
answer++;
cnt[sum]++;
}
return;
}
dfsA(now + 1, sum, selected);
dfsA(now + 1, sum + A[now], selected + 1);
}
void dfsB(int now, int sum, int selected)
{
if (now == B.size())
{
if (selected != 0)
{
if (sum == S)
answer++;
answer += cnt[S - sum];
}
return;
}
dfsB(now + 1, sum, selected);
dfsB(now + 1, sum + B[now], selected + 1);
}
int main()
{
int N, x;
scanf("%d %d", &N, &S);
for (int i = 0; i < N / 2; i++)
{
scanf("%d", &x);
A.push_back(x);
}
for (int i = N / 2; i < N; i++)
{
scanf("%d", &x);
B.push_back(x);
}
dfsA(0, 0, 0);
if (B.size() != 0)
dfsB(0, 0, 0);
printf("%lld\n", answer);
return 0;
}