#include<bits/stdc++.h> using namespace std; constexpr int lim = 10009; constexpr int md = 1000000007; int n,r[3]; char s[lim]; bitset<lim> bt[3],dif; long long sil[lim],pre[lim]; long long pt(long long a,int b,long long c = 1) { while(b) { if(b&1) { c = (a*c)%md; } a = (a*a)%md; b >>= 1; } return c; } inline long long dzie(int a,int b) { return pt(b,md-2,a)%md; } long long dwu(int a,int b) { return dzie(sil[a],sil[b]*sil[a-b]%md); } int main() { scanf("%d", &n); for(int i = 0;i<3;++i) { scanf("%d %s", &r[i], s); for(int j = 0;j<n;++j) { bt[i][j] = s[j]-'0'; } } sil[0] = 1; for(int i = 1;i<=n;++i) { sil[i] = sil[i-1]*i%md; } if(bt[0]==bt[1]) { swap(bt[0],bt[2]); swap(r[0],r[2]); } if(bt[0]==bt[2]) { swap(bt[0],bt[1]); swap(r[0],r[1]); } if(bt[1]==bt[2]) { if(r[1]<r[2]) { swap(r[1],r[2]); } } dif = bt[0]^bt[1]; long long w = 0; int d = dif.count(); pre[0] = 1; for(int i = 1;i<=n;++i) { pre[i] = (pre[i-1]+dwu(n-d,i))%md; } for(int i = 0;i<=d;++i) { int pom = min(r[0]-i,r[1]-d+i); if(pom>=0) { w = (w+dwu(d,i)*pre[pom]%md)%md; } } //* dif = bt[2]^bt[1]; d = dif.count(); for(int i = 1;i<=n;++i) { pre[i] = (pre[i-1]+dwu(n-d,i))%md; } for(int i = 0;i<=d;++i) { int pom = min(r[2]-i,r[1]-d+i); if(pom>=0) { w = (w+dwu(d,i)*pre[pom]%md)%md; } } //*/ w = -w; for(int i = 0;i<=r[0];++i) { w = (w+dwu(n,i))%md; } for(int i = 0;i<=r[1];++i) { w = (w+dwu(n,i))%md; } for(int i = 0;i<=r[2];++i) { w = (w+dwu(n,i))%md; } printf("%lld\n", w); }
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 | #include<bits/stdc++.h> using namespace std; constexpr int lim = 10009; constexpr int md = 1000000007; int n,r[3]; char s[lim]; bitset<lim> bt[3],dif; long long sil[lim],pre[lim]; long long pt(long long a,int b,long long c = 1) { while(b) { if(b&1) { c = (a*c)%md; } a = (a*a)%md; b >>= 1; } return c; } inline long long dzie(int a,int b) { return pt(b,md-2,a)%md; } long long dwu(int a,int b) { return dzie(sil[a],sil[b]*sil[a-b]%md); } int main() { scanf("%d", &n); for(int i = 0;i<3;++i) { scanf("%d %s", &r[i], s); for(int j = 0;j<n;++j) { bt[i][j] = s[j]-'0'; } } sil[0] = 1; for(int i = 1;i<=n;++i) { sil[i] = sil[i-1]*i%md; } if(bt[0]==bt[1]) { swap(bt[0],bt[2]); swap(r[0],r[2]); } if(bt[0]==bt[2]) { swap(bt[0],bt[1]); swap(r[0],r[1]); } if(bt[1]==bt[2]) { if(r[1]<r[2]) { swap(r[1],r[2]); } } dif = bt[0]^bt[1]; long long w = 0; int d = dif.count(); pre[0] = 1; for(int i = 1;i<=n;++i) { pre[i] = (pre[i-1]+dwu(n-d,i))%md; } for(int i = 0;i<=d;++i) { int pom = min(r[0]-i,r[1]-d+i); if(pom>=0) { w = (w+dwu(d,i)*pre[pom]%md)%md; } } //* dif = bt[2]^bt[1]; d = dif.count(); for(int i = 1;i<=n;++i) { pre[i] = (pre[i-1]+dwu(n-d,i))%md; } for(int i = 0;i<=d;++i) { int pom = min(r[2]-i,r[1]-d+i); if(pom>=0) { w = (w+dwu(d,i)*pre[pom]%md)%md; } } //*/ w = -w; for(int i = 0;i<=r[0];++i) { w = (w+dwu(n,i))%md; } for(int i = 0;i<=r[1];++i) { w = (w+dwu(n,i))%md; } for(int i = 0;i<=r[2];++i) { w = (w+dwu(n,i))%md; } printf("%lld\n", w); } |