#include <bits/stdc++.h> using namespace std; int n; int dist(int tmp,int tmp2){ int licznik=0; for (int i=0; i<n;i++){ if ((bool)(tmp & (1<<i)) != (bool)(tmp2 & (1<<i))){ licznik++; } } return licznik; } int main(){ int r[3]; string s[3]; int sr[3]; cin >> n; for (int i=0; i<3;i++){ cin >> r[i]; cin >> s[i]; sr[i]=0; int a=1; for (int j=s[i].size()-1; j>=0;j--){ sr[i]+=a*(s[i][j]-'0'); a*=2; } //cout << sr[i]<<endl; } int wynik=0; int l=1<<n; for (int i=0; i<l;i++){ for (int j=0; j<3;j++){ //cout << sr[j]<<" "<<i<<" "<<r[j]<<" "<<dist(i,sr[j]); if (dist(i,sr[j])<=r[j]){ //cout << "ok"; wynik++; break; } } //cout << endl; } cout << wynik<<endl; }
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 | #include <bits/stdc++.h> using namespace std; int n; int dist(int tmp,int tmp2){ int licznik=0; for (int i=0; i<n;i++){ if ((bool)(tmp & (1<<i)) != (bool)(tmp2 & (1<<i))){ licznik++; } } return licznik; } int main(){ int r[3]; string s[3]; int sr[3]; cin >> n; for (int i=0; i<3;i++){ cin >> r[i]; cin >> s[i]; sr[i]=0; int a=1; for (int j=s[i].size()-1; j>=0;j--){ sr[i]+=a*(s[i][j]-'0'); a*=2; } //cout << sr[i]<<endl; } int wynik=0; int l=1<<n; for (int i=0; i<l;i++){ for (int j=0; j<3;j++){ //cout << sr[j]<<" "<<i<<" "<<r[j]<<" "<<dist(i,sr[j]); if (dist(i,sr[j])<=r[j]){ //cout << "ok"; wynik++; break; } } //cout << endl; } cout << wynik<<endl; } |