#include<cstdio> #include<algorithm> using namespace std; typedef long long LL; const int MX = 10005; const LL M = 1000000007; int n; bool a[MX], b[MX], c[MX]; int t[MX][MX]; int ra, rb, rc; void init() { t[0][0] = t[1][0] = t[1][1] = 1; for (int i=2; i<=n; i++) { t[i][0] = t[i][i] = 1; for (int j=1; j<i; j++) t[i][j] = ((LL)t[i-1][j-1] + (LL)t[i-1][j]) % M; } } void read(int &r, bool *v) { scanf("%d ", &r); for (int i=0; i<n; i++) { char c; scanf("%c", &c); v[i] = (c == '1'); } } int main() { scanf("%d", &n); init(); read(ra, a); read(rb, b); read(rc, c); for (int i=0; i<n; i++) b[i] ^= a[i]; for (int i=0; i<n; i++) c[i] ^= a[i]; int x=0, y=0, z=0, w=0; for (int i=0; i<n; i++) { if (b[i]) ++x; if (c[i]) ++y; if (b[i] != c[i]) ++z; else if (b[i]) ++w; } if (x == 0 && ra == rb) x = y, rb = rc; // a==b, use c instead LL q=0; for (int i=0; i<=ra; i++) { int s = x-i; if (s >= 0) { for (int j=s, k=0; j<=rb && (s+k)<=x; j+=2, k++) { q += (LL)t[x][s+k] * (LL)t[n-x][k]; q %= M; } } else { s = i - x; for (int j=s, k=0; j<=rb && k<=x; j+=2, k++) { q += (LL)t[x][k] * (LL)t[n-x][s+k]; q %= M; } } } printf("%lld\n", q); 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 | #include<cstdio> #include<algorithm> using namespace std; typedef long long LL; const int MX = 10005; const LL M = 1000000007; int n; bool a[MX], b[MX], c[MX]; int t[MX][MX]; int ra, rb, rc; void init() { t[0][0] = t[1][0] = t[1][1] = 1; for (int i=2; i<=n; i++) { t[i][0] = t[i][i] = 1; for (int j=1; j<i; j++) t[i][j] = ((LL)t[i-1][j-1] + (LL)t[i-1][j]) % M; } } void read(int &r, bool *v) { scanf("%d ", &r); for (int i=0; i<n; i++) { char c; scanf("%c", &c); v[i] = (c == '1'); } } int main() { scanf("%d", &n); init(); read(ra, a); read(rb, b); read(rc, c); for (int i=0; i<n; i++) b[i] ^= a[i]; for (int i=0; i<n; i++) c[i] ^= a[i]; int x=0, y=0, z=0, w=0; for (int i=0; i<n; i++) { if (b[i]) ++x; if (c[i]) ++y; if (b[i] != c[i]) ++z; else if (b[i]) ++w; } if (x == 0 && ra == rb) x = y, rb = rc; // a==b, use c instead LL q=0; for (int i=0; i<=ra; i++) { int s = x-i; if (s >= 0) { for (int j=s, k=0; j<=rb && (s+k)<=x; j+=2, k++) { q += (LL)t[x][s+k] * (LL)t[n-x][k]; q %= M; } } else { s = i - x; for (int j=s, k=0; j<=rb && k<=x; j+=2, k++) { q += (LL)t[x][k] * (LL)t[n-x][s+k]; q %= M; } } } printf("%lld\n", q); return 0; } |