#include<bits/stdc++.h> using namespace std; void xd(int n) { long long ans=1; for(int i=0;i^n;++i) { ans<<=1; ans%=(long long)(1e9+7); } printf("%lld", ans); } int main() { unsigned int n, r, r1, r2; unsigned int w=0, w1=0, w2=0; char c=0; scanf("%u%u", &n, &r); if(n>31) { xd(n); return 0; } n=(1<<n); while(c!='1' && c!='0') { c=getchar(); } do { w<<=1; w+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); scanf("%u", &r1); while(c!='1' && c!='0') { c=getchar(); } do { w1<<=1; w1+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); scanf("%u", &r2); while(c!='1' && c!='0') { c=getchar(); } do { w2<<=1; w2+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); unsigned int k, ans=0; for(unsigned int i=0;i^n;++i) { k=__builtin_popcount(i^w); if(k<=r) { ++ans; continue; } k=__builtin_popcount(i^w1); if(k<=r1) { ++ans; continue; } k=__builtin_popcount(i^w2); if(k<=r2) ++ans; } printf("%u", ans%(int)(1e9+7)); 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 | #include<bits/stdc++.h> using namespace std; void xd(int n) { long long ans=1; for(int i=0;i^n;++i) { ans<<=1; ans%=(long long)(1e9+7); } printf("%lld", ans); } int main() { unsigned int n, r, r1, r2; unsigned int w=0, w1=0, w2=0; char c=0; scanf("%u%u", &n, &r); if(n>31) { xd(n); return 0; } n=(1<<n); while(c!='1' && c!='0') { c=getchar(); } do { w<<=1; w+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); scanf("%u", &r1); while(c!='1' && c!='0') { c=getchar(); } do { w1<<=1; w1+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); scanf("%u", &r2); while(c!='1' && c!='0') { c=getchar(); } do { w2<<=1; w2+=(c-'0'); c=getchar(); } while(c=='1' || c=='0'); unsigned int k, ans=0; for(unsigned int i=0;i^n;++i) { k=__builtin_popcount(i^w); if(k<=r) { ++ans; continue; } k=__builtin_popcount(i^w1); if(k<=r1) { ++ans; continue; } k=__builtin_popcount(i^w2); if(k<=r2) ++ans; } printf("%u", ans%(int)(1e9+7)); return 0; } |