#include<iostream> #include<cmath> #include<vector> using namespace std; void BinaryIncrease(string &s,int index) { if(s[index]=='1') { s[index]='0'; if(index==0) { s='1'+s; } else { BinaryIncrease(s,index-1); } } else { s[index]='1'; } } int IleJedynek(string s) { int ans = 0; for(int i=0;i<s.length();i++) { if(s[i]=='1') ans++; } return ans; } string XOR(string s1,string s2) { string out = ""; for(int i=0;i<s1.length();i++) { if(s1[i]!=s2[i]) { out+='1'; } else { out+='0'; } } return out; } int main() { int n; cin>>n; vector<int> r; vector<string> s; for(int i=0;i<3;i++) { int rr; string ss; cin>>rr>>ss; r.push_back(rr); s.push_back(ss); } uint64_t ans = 0; string w = "1"; for(int i=0;i<n;i++) { w+='0'; } while(1) { if(w.length()>n+1) break; string wierzcholek = ""; for(int i=1;i<w.length();i++) { wierzcholek+=w[i]; } for(int i=0;i<s.size();i++) { int ile = IleJedynek(XOR(wierzcholek,s[i])); if(ile<=r[i]) { ans++; break; } } BinaryIncrease(w,w.length()-1); } cout<<ans; 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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #include<iostream> #include<cmath> #include<vector> using namespace std; void BinaryIncrease(string &s,int index) { if(s[index]=='1') { s[index]='0'; if(index==0) { s='1'+s; } else { BinaryIncrease(s,index-1); } } else { s[index]='1'; } } int IleJedynek(string s) { int ans = 0; for(int i=0;i<s.length();i++) { if(s[i]=='1') ans++; } return ans; } string XOR(string s1,string s2) { string out = ""; for(int i=0;i<s1.length();i++) { if(s1[i]!=s2[i]) { out+='1'; } else { out+='0'; } } return out; } int main() { int n; cin>>n; vector<int> r; vector<string> s; for(int i=0;i<3;i++) { int rr; string ss; cin>>rr>>ss; r.push_back(rr); s.push_back(ss); } uint64_t ans = 0; string w = "1"; for(int i=0;i<n;i++) { w+='0'; } while(1) { if(w.length()>n+1) break; string wierzcholek = ""; for(int i=1;i<w.length();i++) { wierzcholek+=w[i]; } for(int i=0;i<s.size();i++) { int ile = IleJedynek(XOR(wierzcholek,s[i])); if(ile<=r[i]) { ans++; break; } } BinaryIncrease(w,w.length()-1); } cout<<ans; return 0; } |