-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsubsequence.cpp
More file actions
50 lines (45 loc) · 1.19 KB
/
Copy pathsubsequence.cpp
File metadata and controls
50 lines (45 loc) · 1.19 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
#include<bits/stdc++.h>
using namespace std;
int main () {
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
vector<int> arr(n);
for(int i = 0; i<n ;i++) cin>>arr[i];
for(auto i: arr) cout<<i<<" ";
cout<<endl;
int ans=0;
for(int i = 0; i<=((1<<n)-1);i++) {
// cout<<"i = "<<i<<endl;
// check set bit
int sum = 0;
int prev = -1;
int first = 0, last = 0;
for(int j = 0 ; j < n;j++) {
if(i&(1<<j)){
cout<<i<<" "<<j<<endl;
cout<<j<<" ";
if(prev==-1) {
first = arr[j];
sum = 0;
} else {
// cout<<arr[prev]<<" "<<arr[j]<<endl;
sum += (arr[prev] - arr[j]);
}
prev = j;
last = arr[j];
} else {
cout<<"0"<<" ";
}
}
cout<<endl;
// cout<<"last = "<<last<<" "<<first<<endl;
// cout<<sum<<" "<<(last-first)<<" "<<last<<" "<<first<<endl;
if( (last-first) != sum ) ans++;
}
cout<<ans<<endl;
}
return 0;
}