-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsumSubsets.cpp
More file actions
51 lines (37 loc) · 906 Bytes
/
sumSubsets.cpp
File metadata and controls
51 lines (37 loc) · 906 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
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6;
const int MAXLOG=20;
void solve(){
int n;
cin>>n;
int arr[n];
int forward1[MAXN]={0};
int forward2[MAXN]={0};
for(int i=0; i<n; i++){
cin>>arr[i];
forward1[arr[i]]++;
forward2[arr[i]]++;
}
for(int i=0;i<=MAXLOG; i++){
for(int j=0;j<MAXN; j++){
if(j&(1<<i)) {
forward1[j]+=forward1[j^(1<<i)]; //adding value of subsets to the super set
}
}
}
for(int i=0;i<=MAXLOG; i++){
for(int j=MAXN-1;j>=0; j--){
if(j&(1<<i)) {
forward1[j^(1<<i)]+=forward1[j]; //adding value of supersets to the subset
}
}
}
//problem find all super sets of zero
// cout<<forward2[0]<<endl;
}
int main(){
int t; cin>>t;
for(int i=0;i<t;i++) solve();
return 0;
}