#include <bits/stdc++.h> using namespace std; int diff(unsigned long long a, unsigned long long b) { unsigned long long c = a ^ b; int d = 0; while (c > 0) { if (c % 2 == 1) d++; c /= 2; } return d; } unsigned long long X(string A) { unsigned long long R = 0; for(int i = A.size() - 1; i >= 0; i--) { R *= 2; R += (A[i] - '0'); } return R; } void solve() { int N, a, b, c; cin >> N; string x, y, z; unsigned long long A, B, C; cin >> a >> x >> b >> y >> c >> z; unsigned long long mask = 0; unsigned long long res = 0; A = X(x); B = X(y); C = X(z); while (mask < (1 << N)) { if(diff(mask, A) <= a || diff(mask, B) <= b || diff(mask, C) <= c) res++; mask++; } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
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 | #include <bits/stdc++.h> using namespace std; int diff(unsigned long long a, unsigned long long b) { unsigned long long c = a ^ b; int d = 0; while (c > 0) { if (c % 2 == 1) d++; c /= 2; } return d; } unsigned long long X(string A) { unsigned long long R = 0; for(int i = A.size() - 1; i >= 0; i--) { R *= 2; R += (A[i] - '0'); } return R; } void solve() { int N, a, b, c; cin >> N; string x, y, z; unsigned long long A, B, C; cin >> a >> x >> b >> y >> c >> z; unsigned long long mask = 0; unsigned long long res = 0; A = X(x); B = X(y); C = X(z); while (mask < (1 << N)) { if(diff(mask, A) <= a || diff(mask, B) <= b || diff(mask, C) <= c) res++; mask++; } cout << res << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); } |