-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_Cost_too_Great.cpp
More file actions
73 lines (70 loc) · 1.26 KB
/
No_Cost_too_Great.cpp
File metadata and controls
73 lines (70 loc) · 1.26 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
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
#define MOD 676767677
#define int long long
vector<vector<int>> combinations(int sz)
{
int comb = 1 << sz;
vector<vector<int>> all;
for (int mask = 0; mask < comb; mask++)
{
vector<int> bits;
for (int j = sz - 1; j >= 0; j--)
{
int bit = (mask >> j) & 1;
bits.push_back(bit ? 1 : -1);
}
all.push_back(bits);
}
return all;
}
void solve(int arr[],int sz)
{
int ans=0;
vector<vector<int>> sol = combinations(sz);
for(int i=0;i<sol.size();i++)
{
bool correct = false;
for(int j=0;j<sol[i].size();j++)
{
int check = arr[j];
int sum = 0;
for(int k=0;k<sol[i].size();k++)
{
if(k<=j)
{
if(sol[i][k]==-1) sum++;
}
if(k>=j)
{
if(sol[i][k]==1) sum++;
}
}
if(check!=sum)
{
correct = false;
break;
}
if(j==sz-1) correct=true;
}
if(correct == true) ans++;
}
cout<<(ans%MOD)<<endl;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--)
{
int sz;
cin>>sz;
int arr[sz];
for(int i=0;i<sz;i++)
cin>>arr[i];
solve(arr,sz);
}
return 0;
}