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
#include <bits/stdc++.h>
using namespace std;
map <vector<int>, bool> czyjest;

vector<int> V1;
vector<int> V2;
vector<int> V3;
vector<int> Vall;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, r1, r2, r3, wyn = 0;
    string k1, k2, k3;
    cin >> n >> r1 >> k1 >> r2 >> k2 >> r3 >> k3;

    for (int i = n - 1; i > -1; --i)
    {
        V1.push_back(k1[i] - '0');
        V2.push_back(k2[i] - '0');
        V3.push_back(k3[i] - '0');
    }
    for (int b = 0; b < (1 << n); ++b)
    {
        Vall.resize(0);
        long long licz = 0, licz2 = 0, licz3 = 0, ile = 0;
        for (int i = 0; i < n; i++)
        {
            if (b & (1 << i)) Vall.push_back(1);
            else Vall.push_back(0);
        }
        if (czyjest[Vall] == 0)
        {
            for (int k = 0; k < n; ++k)
                if (V1[k] != Vall[k]) ++licz;
            if (licz <= r1)
            {
                czyjest[Vall] = 1;
                ile = 1;
            }
        }
        if (czyjest[Vall] == 0)
        {
            for (int k = 0; k < n; ++k)
                if (V2[k] != Vall[k]) ++licz2;
            if (licz2 <= r2)
            {
                czyjest[Vall] = 1;
                ile = 1;
            }
        }
        if (czyjest[Vall] == 0)
        {
            for (int k = 0; k < n; ++k)
                if (V3[k] != Vall[k]) ++licz3;
            if (licz3 <= r3)
            {
                czyjest[Vall] = 1;
                ile = 1;
            }
        }
        wyn += ile;
        wyn %= 1000000007;
    }

    cout << wyn << '\n';
    return 0;
}