-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCC-BINXOR.cpp
More file actions
79 lines (64 loc) · 1.38 KB
/
CC-BINXOR.cpp
File metadata and controls
79 lines (64 loc) · 1.38 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
74
75
76
77
78
79
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
long long fac[100001];
long long power(long long x, long long y, long long p){
long long res = 1;
x = x % p;
while (y > 0){
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
long long modInverse(long long n, long long p){
return power(n, p-2, p);
}
long long nCrModPFermat(long long n,long long r, long long p){
if (r==0)
return 1;
//(a*b)%m = (a%m*b%m)%m
return ((fac[n]%p)* (modInverse(fac[r], p) % p)%p * (modInverse(fac[n-r], p) % p)) % p;
}
int main(){
long long p = 1e9+7;
fac[0] = 1;
for (int i=1 ; i<=100000; i++)
fac[i] = ((fac[i-1]%p)*(i%p))%p;
int t;
cin >> t;
for(int s=0;s<t;s++){
long long n;
cin >> n;
string a , b;
cin >> a >> b;
long long Cmax=0,Cmin=0,n2=0,n1=0;
for(int i=0;i<n;i++){
if(a[i]=='1')
n1++;
if(b[i]=='1')
n2++;
}
long long small = min(n1,n2);
long long big = max(n1,n2);
Cmin = big - small;
if(small + big > n){
Cmax = (2*n) - (small + big);
}
else{
Cmax = small + big;
}
Cmin = abs(n2 - n1);
long long total = 0;
for(int i = Cmin;i <= Cmax;i += 2){
total += nCrModPFermat(n,i,p);
}
cout << total << "\n";
// cout << "Max " << Cmax << "\n";
// cout << "Min " << Cmin << "\n";
}
return 0;
}