#include <iostream>
using namespace std;
struct K
{
int ma, ks;
bool spelnia(int i)
{
return (i&ma)^ks;
}
} k[1000000];
int lk=0;
bool wczytaj()
{
char c;
cin>>c;
if (c=='^')
return true;
if (c!='(')
return false;
int ma=0, ks=0;
for (; ; )
{
cin>>c;
int x;
switch (c)
{
case '~':
cin>>c;
cin>>x;
--x;
ma|=(1<<x);
ks|=(1<<x);
break;
case 'x':
cin>>x;
--x;
ma|=(1<<x);
break;
case 'v':
break;
case ')':
k[lk].ma=ma;
k[lk++].ks=ks;
return true;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
if (30<n)
{
cout<<0<<endl;
return 0;
}
while (wczytaj())
;
int wyn=0;
for (int i=0, kon=(1<<n); i<kon; ++i)
{
bool ok=true;
for (int j=0; j<lk; ++j)
if (!k[j].spelnia(i))
{
ok=false;
break;
}
if (ok)
++wyn;
}
cout<<(wyn%1000000007)<<endl;
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 | #include <iostream> using namespace std; struct K { int ma, ks; bool spelnia(int i) { return (i&ma)^ks; } } k[1000000]; int lk=0; bool wczytaj() { char c; cin>>c; if (c=='^') return true; if (c!='(') return false; int ma=0, ks=0; for (; ; ) { cin>>c; int x; switch (c) { case '~': cin>>c; cin>>x; --x; ma|=(1<<x); ks|=(1<<x); break; case 'x': cin>>x; --x; ma|=(1<<x); break; case 'v': break; case ')': k[lk].ma=ma; k[lk++].ks=ks; return true; } } } int main() { ios_base::sync_with_stdio(false); int n; cin>>n; if (30<n) { cout<<0<<endl; return 0; } while (wczytaj()) ; int wyn=0; for (int i=0, kon=(1<<n); i<kon; ++i) { bool ok=true; for (int j=0; j<lk; ++j) if (!k[j].spelnia(i)) { ok=false; break; } if (ok) ++wyn; } cout<<(wyn%1000000007)<<endl; return 0; } |
English