#include <iostream> #include <vector> using namespace std; int res=0; int n; int k=0; string a; vector<int>V[10000001]; bool tab[10000000]; void read_and_prepare() { cin>>n; cin.ignore(); getline(cin,a); for(unsigned int i=0;i<a.size();i++) { if(a[i]=='(') { while(a[i]!=')') { if(a[i]=='x') { int x=0; i++; while((int)a[i]>=48 && (int)a[i]<=57) { x*=10; x+=(int)a[i]-48; i++; } V[k].push_back(2*x); i--; }else if(a[i]=='~') { int x=0; i+=2; while((int)a[i]>=48 && (int)a[i]<=57) { x*=10; x+=(int)a[i]-48; i++; } V[k].push_back(2*x+1); i--; } i++; } k++; } } } bool check() { for(int i=0;i<k;i++) { bool flag=0; for(unsigned int j=0;j<V[i].size();j++) { if(tab[V[i][j]]) { flag=1; break; } } if(!flag)return false; } return true; } void solve(int i,bool x) { tab[2*i]=x; tab[2*i+1]=!x; if(i==n)if(check())res++; if(i<n) { solve(i+1,0); solve(i+1,1); } } int main() { ios_base::sync_with_stdio(0); read_and_prepare(); solve(0,0); cout<<res; }
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 | #include <iostream> #include <vector> using namespace std; int res=0; int n; int k=0; string a; vector<int>V[10000001]; bool tab[10000000]; void read_and_prepare() { cin>>n; cin.ignore(); getline(cin,a); for(unsigned int i=0;i<a.size();i++) { if(a[i]=='(') { while(a[i]!=')') { if(a[i]=='x') { int x=0; i++; while((int)a[i]>=48 && (int)a[i]<=57) { x*=10; x+=(int)a[i]-48; i++; } V[k].push_back(2*x); i--; }else if(a[i]=='~') { int x=0; i+=2; while((int)a[i]>=48 && (int)a[i]<=57) { x*=10; x+=(int)a[i]-48; i++; } V[k].push_back(2*x+1); i--; } i++; } k++; } } } bool check() { for(int i=0;i<k;i++) { bool flag=0; for(unsigned int j=0;j<V[i].size();j++) { if(tab[V[i][j]]) { flag=1; break; } } if(!flag)return false; } return true; } void solve(int i,bool x) { tab[2*i]=x; tab[2*i+1]=!x; if(i==n)if(check())res++; if(i<n) { solve(i+1,0); solve(i+1,1); } } int main() { ios_base::sync_with_stdio(0); read_and_prepare(); solve(0,0); cout<<res; } |