-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASSIGN.cpp
More file actions
79 lines (77 loc) · 944 Bytes
/
ASSIGN.cpp
File metadata and controls
79 lines (77 loc) · 944 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <vector>
using namespace std;
long long a,b,z;
vector <long long> v;
long long dp[1<<20];
long long n,t;
long long count_b(long long f)
{
int ct=0;
while(f>0)
{
f=f&(f-1);
ct++;
}
return ct;
}
void init()
{
v.clear();
long long j;
for(j=0;j<(1<<20);j++)
{
dp[j]=-1;
}
}
long long solve(int x,int y)
{
long ctb=count_b(y);
if(x!=ctb)
{
return 0;
}
if(x==n && ctb==x)
{
return 1;
}
else if(dp[y]!=-1)
{
return dp[y];
}
else
{
long long i;
dp[y]=0;
for(i=0;i<n;i++)
{
if((((1<<i)&v[x])!=0) && (((1<<i)&y)==0))
{
dp[y]+= solve(x+1,(1<<i)|y);
}
}
return dp[y];
}
}
int main() {
// your code goes here
cin>>t;
long long res=0;
while(t--)
{
init();
cin>>n;
for(a=0;a<n;a++)
{
res=0;
for(b=0;b<n;b++)
{
cin>>z;
res=(2*res)+z;
}
v.push_back(res);
}
cout<<solve(0,0)<<endl;
}
return 0;
}