// // main.cpp // kul // // Created by Mikołaj Korulczyk on 14/12/2019. // Copyright © 2019 Mikołaj Korulczyk. All rights reserved. // #include <bits/stdc++.h> using namespace std; unsigned int n; unsigned int r[4]; string point[4]; unsigned int p[4]; bool c; unsigned int mod = 1e9+7; unsigned int chck; unsigned int counter; const int N = 1e5; long long A[N], B[N]; set<pair<int, string> > sp; long long pre(long long n, long long p) { if(!p) { return 1LL; } if(p&1) { return ((n%mod)*pre(n, p-1))%mod; } long long a = pre(n, p/2); return (a*a)%mod; } int nCr(int n, int r) { if(r < 0 || r > n) { return 0; } //cout << n << r << endl; //cout << (A[n]*((B[n-r]*B[r])%mod))%mod << endl; return (A[n]*((B[n-r]*B[r])%mod))%mod; } unsigned int calc_bits(unsigned int n) { unsigned int c = 0; while(n) { c += n&1; n >>= 1; } return c; } int cp(int r1, int r2, int common, int different) { int res = 0; int cc = 0; while(r1+r2 >= different) { int ds = 0; int cs = nCr(common, cc); int r1a = r1; int r2a = r2; while(r1a+r2a >= different) { if(r1a < different) { ds = (ds + nCr(different, r1a))%mod; r1a--; } else { ds = (ds+(long long)pow(2, different))%mod; break; } } res = (res+(cs*ds)%mod)%mod; cc++; r1--; r2--; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); A[0] = 1; A[1] = 1; B[0] = 1; B[1] = 1; for(int i = 2; i < N; i++){ A[i] = (A[i-1]*i)%mod; B[i] = (B[i-1]*pre((long long)i, mod-2))%mod; } cin >> n; for(int i = 1; i <= 3; i++) { cin >> r[i] >> point[i]; sp.insert(make_pair(r[i], point[i])); for(auto j: point[i]) { p[i] += j-'0'; p[i] <<= 1; } p[i] >>= 1; } if(sp.size() == 3) { counter = 0; for(int i = 0; i < pow(2, n); i++) { c = false; for(int j = 1; j <= 3; j++) { chck = calc_bits(i^p[j]); if(chck <= r[j]) { c = true; } } counter += c; counter %= mod; } cout << (counter%mod) << "\n"; return 0; } r[1] = (*sp.begin()).first; point[1] = (*sp.begin()).second; sp.erase(sp.begin()); if(sp.size()) { r[2] = (*sp.begin()).first; point[2] = (*sp.begin()).second; } else { r[2] = r[1]; point[2] = point[1]; } int com = 0; int dif; for(int i = 0; i < n; i++) { if(point[1][i] == point[2][i]) { com++; } } dif = n-com; int s1 = 0; int s2 = 0; int sub = cp(min(r[1], r[2]), max(r[1], r[2]), com, dif)%mod; for(int i = 0; i <= r[1]; i++) { s1 += nCr(n, i)%mod; s1 %= mod; } for(int i = 0; i <= r[2]; i++) { s2 += nCr(n, i)%mod; s2 %= mod; } //cout << s1 << endl; //cout << s2 << endl; //cout << sub << endl; cout << ((s1%mod)+(s2%mod)-(sub%mod))%mod << "\n"; return 0; }
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | // // main.cpp // kul // // Created by Mikołaj Korulczyk on 14/12/2019. // Copyright © 2019 Mikołaj Korulczyk. All rights reserved. // #include <bits/stdc++.h> using namespace std; unsigned int n; unsigned int r[4]; string point[4]; unsigned int p[4]; bool c; unsigned int mod = 1e9+7; unsigned int chck; unsigned int counter; const int N = 1e5; long long A[N], B[N]; set<pair<int, string> > sp; long long pre(long long n, long long p) { if(!p) { return 1LL; } if(p&1) { return ((n%mod)*pre(n, p-1))%mod; } long long a = pre(n, p/2); return (a*a)%mod; } int nCr(int n, int r) { if(r < 0 || r > n) { return 0; } //cout << n << r << endl; //cout << (A[n]*((B[n-r]*B[r])%mod))%mod << endl; return (A[n]*((B[n-r]*B[r])%mod))%mod; } unsigned int calc_bits(unsigned int n) { unsigned int c = 0; while(n) { c += n&1; n >>= 1; } return c; } int cp(int r1, int r2, int common, int different) { int res = 0; int cc = 0; while(r1+r2 >= different) { int ds = 0; int cs = nCr(common, cc); int r1a = r1; int r2a = r2; while(r1a+r2a >= different) { if(r1a < different) { ds = (ds + nCr(different, r1a))%mod; r1a--; } else { ds = (ds+(long long)pow(2, different))%mod; break; } } res = (res+(cs*ds)%mod)%mod; cc++; r1--; r2--; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); A[0] = 1; A[1] = 1; B[0] = 1; B[1] = 1; for(int i = 2; i < N; i++){ A[i] = (A[i-1]*i)%mod; B[i] = (B[i-1]*pre((long long)i, mod-2))%mod; } cin >> n; for(int i = 1; i <= 3; i++) { cin >> r[i] >> point[i]; sp.insert(make_pair(r[i], point[i])); for(auto j: point[i]) { p[i] += j-'0'; p[i] <<= 1; } p[i] >>= 1; } if(sp.size() == 3) { counter = 0; for(int i = 0; i < pow(2, n); i++) { c = false; for(int j = 1; j <= 3; j++) { chck = calc_bits(i^p[j]); if(chck <= r[j]) { c = true; } } counter += c; counter %= mod; } cout << (counter%mod) << "\n"; return 0; } r[1] = (*sp.begin()).first; point[1] = (*sp.begin()).second; sp.erase(sp.begin()); if(sp.size()) { r[2] = (*sp.begin()).first; point[2] = (*sp.begin()).second; } else { r[2] = r[1]; point[2] = point[1]; } int com = 0; int dif; for(int i = 0; i < n; i++) { if(point[1][i] == point[2][i]) { com++; } } dif = n-com; int s1 = 0; int s2 = 0; int sub = cp(min(r[1], r[2]), max(r[1], r[2]), com, dif)%mod; for(int i = 0; i <= r[1]; i++) { s1 += nCr(n, i)%mod; s1 %= mod; } for(int i = 0; i <= r[2]; i++) { s2 += nCr(n, i)%mod; s2 %= mod; } //cout << s1 << endl; //cout << s2 << endl; //cout << sub << endl; cout << ((s1%mod)+(s2%mod)-(sub%mod))%mod << "\n"; return 0; } |