-
Notifications
You must be signed in to change notification settings - Fork 0
/
1208.cpp
55 lines (45 loc) · 763 Bytes
/
1208.cpp
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
#include<iostream>
#include<vector>
#include<map>
#define N 55
using namespace std;
typedef map<int, int> intmap;
int n, s;
long long ans=0;
vector<int> arr;
intmap ls;
void l(int index, int sum)
{
if(index==n/2){
ls[sum]++;
return;
}
l(index+1, sum);
l(index+1, sum+arr[index]);
}
void r(int index, int sum)
{
if(index==n){
ans += ls[s-sum];
return;
}
r(index+1, sum);
r(index+1, sum+arr[index]);
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int i, j;
cin >> n >> s;
for(i=0; i<n; i++){
int a;
cin >> a;
arr.push_back(a);
}
l(0, 0);
r(n/2, 0);
if(s==0) ans--;
cout << ans;
return 0;
}