#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; #define MAX_N 1000000 #define MOD 1000000007 int n; string str; vector<vector<pair<int, bool>>> data; int ret = 0; int D[MAX_N]; void f(int i){ if(i < n){ D[i] = 0; f(i + 1); D[i] = 1; f(i + 1); }else{ bool all = 1; for(auto& v : data){ bool any = 0; for(auto& p : v){ if(p.second ^ D[p.first]){ any = 1; break; } } if(!any){ all = 0; break; } } if(all){ if(++ret >= MOD)ret -= MOD; } } } int main(){ ios::sync_with_stdio(0); cin>>n; getline(cin, str); getline(cin, str); int value = 0; bool neg = 0; for(int a=0; a<int(str.size()); ++a){ if(str[a] >= '0' && str[a] <= '9'){ value = value * 10 + (str[a] - '0'); }else{ if(value != 0)data.back().push_back({value - 1, neg}); if(str[a] != 'x'){ value = 0; neg = 0; } if(str[a] == '('){ data.push_back({}); }else if(str[a] == '~'){ neg = 1; } } } f(0); cout<<ret; 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 | #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; #define MAX_N 1000000 #define MOD 1000000007 int n; string str; vector<vector<pair<int, bool>>> data; int ret = 0; int D[MAX_N]; void f(int i){ if(i < n){ D[i] = 0; f(i + 1); D[i] = 1; f(i + 1); }else{ bool all = 1; for(auto& v : data){ bool any = 0; for(auto& p : v){ if(p.second ^ D[p.first]){ any = 1; break; } } if(!any){ all = 0; break; } } if(all){ if(++ret >= MOD)ret -= MOD; } } } int main(){ ios::sync_with_stdio(0); cin>>n; getline(cin, str); getline(cin, str); int value = 0; bool neg = 0; for(int a=0; a<int(str.size()); ++a){ if(str[a] >= '0' && str[a] <= '9'){ value = value * 10 + (str[a] - '0'); }else{ if(value != 0)data.back().push_back({value - 1, neg}); if(str[a] != 'x'){ value = 0; neg = 0; } if(str[a] == '('){ data.push_back({}); }else if(str[a] == '~'){ neg = 1; } } } f(0); cout<<ret; return 0; } |