#include <bits/stdc++.h> using namespace std; int n; string s; vector<vector<int> > tab; bool tr(int values[]) { bool final = true; for(int i = 0; i < tab.size(); i++) { bool res = false; for(int j = 0; j < tab[i].size(); j++) { if(tab[i][j] < 0) res |= !values[-tab[i][j] - 1]; else res |= values[tab[i][j] - 1]; } final &= res; } return final; } int main() { scanf("%d", &n); getline(cin, s); getline(cin, s); vector<int> temp; int temp2 = 0; bool inv = false; for(int i = 0; i < s.size(); i++) { if(s[i] == ')') { temp.push_back(inv ? -temp2 : temp2); inv = false; temp2 = 0; tab.push_back(temp); temp.clear(); } else if(s[i] == 'v') { temp.push_back(inv ? -temp2 : temp2); inv = false; temp2 = 0; } else if(s[i] == '~') { inv = true; } else if(s[i] >= '0' && s[i] <= '9') { temp2 *= 10; temp2 += s[i] - '0'; } } int counter = 0; for(int i = 0; i < (1 << n); i++) { int tab3[100] = {}; for(int j = 0; j < n; j++) tab3[j] = i & (1 << j); if(tr(tab3)) counter++; } printf("%d", counter); 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 | #include <bits/stdc++.h> using namespace std; int n; string s; vector<vector<int> > tab; bool tr(int values[]) { bool final = true; for(int i = 0; i < tab.size(); i++) { bool res = false; for(int j = 0; j < tab[i].size(); j++) { if(tab[i][j] < 0) res |= !values[-tab[i][j] - 1]; else res |= values[tab[i][j] - 1]; } final &= res; } return final; } int main() { scanf("%d", &n); getline(cin, s); getline(cin, s); vector<int> temp; int temp2 = 0; bool inv = false; for(int i = 0; i < s.size(); i++) { if(s[i] == ')') { temp.push_back(inv ? -temp2 : temp2); inv = false; temp2 = 0; tab.push_back(temp); temp.clear(); } else if(s[i] == 'v') { temp.push_back(inv ? -temp2 : temp2); inv = false; temp2 = 0; } else if(s[i] == '~') { inv = true; } else if(s[i] >= '0' && s[i] <= '9') { temp2 *= 10; temp2 += s[i] - '0'; } } int counter = 0; for(int i = 0; i < (1 << n); i++) { int tab3[100] = {}; for(int j = 0; j < n; j++) tab3[j] = i & (1 << j); if(tr(tab3)) counter++; } printf("%d", counter); return 0; } |