#include <cstdio> #include <cstdlib> using namespace std; const int N_MAX = 10000; const int MODULO = 1000000000 + 7; int S[N_MAX]; int R[3]; int Kostka[3][N_MAX]; int result = 0; void printS(int n) { printf("%d\n", n); for (int i = 0; i < n; ++i) { printf("%d", S[i]); } printf("\n"); } void printKostka(int x, int n) { printf("%d\n", n); for (int i = 0; i < n; ++i) { printf("%d", Kostka[x][i]); } printf("\n"); } bool g(int n, int id) { int diff = 0; for (int i = 0; i < n; ++i) { diff += Kostka[id][i] != S[i]; } return diff <= R[id]; } void check(int n) { for (int i = 0; i < 3; ++i) { if (g(n, i)) { result = (result + 1) % MODULO; return; } } } void f(int n, int x) { if (x < n) { S[x] = 0; f(n, x + 1); S[x] = 1; f(n, x + 1); } if (x == n) { check(n); } } int main() { int n; scanf("%d", &n); for (int i = 0; i < 3; ++i) { scanf("%d", &R[i]); getchar(); for (int j = 0; j < n; ++j) { char c = getchar(); Kostka[i][j] = c == '1'; } } f(n, 0); printf("%d\n", result); 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 | #include <cstdio> #include <cstdlib> using namespace std; const int N_MAX = 10000; const int MODULO = 1000000000 + 7; int S[N_MAX]; int R[3]; int Kostka[3][N_MAX]; int result = 0; void printS(int n) { printf("%d\n", n); for (int i = 0; i < n; ++i) { printf("%d", S[i]); } printf("\n"); } void printKostka(int x, int n) { printf("%d\n", n); for (int i = 0; i < n; ++i) { printf("%d", Kostka[x][i]); } printf("\n"); } bool g(int n, int id) { int diff = 0; for (int i = 0; i < n; ++i) { diff += Kostka[id][i] != S[i]; } return diff <= R[id]; } void check(int n) { for (int i = 0; i < 3; ++i) { if (g(n, i)) { result = (result + 1) % MODULO; return; } } } void f(int n, int x) { if (x < n) { S[x] = 0; f(n, x + 1); S[x] = 1; f(n, x + 1); } if (x == n) { check(n); } } int main() { int n; scanf("%d", &n); for (int i = 0; i < 3; ++i) { scanf("%d", &R[i]); getchar(); for (int j = 0; j < n; ++j) { char c = getchar(); Kostka[i][j] = c == '1'; } } f(n, 0); printf("%d\n", result); return 0; } |