//parse test #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PI; typedef vector<PI> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif int n, m, k, l, test = 1; const int INF = 1000 * 1000 * 1000; const int MAKSN = 1000 * 1000 + 13; // UZUPElnic const LL MOD = INF + 7; // nr, czy negacja vector<vector<pair<int, bool> > > v; void parseLine(); void parseBracket(); void readIn() { l = scanf("%d", &n); parseLine(); } void parseLine() { char c; l = scanf("%c",&c); // '\n' while (true) { l = scanf("%c", &c); if (c == '\n') return; if (c == '(') parseBracket(); } } int parseX() { int temp; l = scanf("%d", &temp); return temp; } void parseBracket() { vector<pair<int, bool> > temp; char c ='0'; int num; bool krulBul; // printf("Tag\n"/); // printf("("); while(true) { l = scanf("%c", &c); // printf("%c",c); krulBul = false; if(c == '~') { krulBul = true; l = scanf("%c", &c); //x // printf("%c",c); } if(c == 'x') { num = parseX(); // printf("%d ", num); temp.PB(MP(num, krulBul)); } if(c == ')') break; // printf( "\n"); } // printf("temp %d \n", (int)temp.size()); v.PB(temp); } void printOut() { REP(i, v.size()) { printf("("); REP(j, v[i].size()) { int num; bool b; num = v[i][j].ST; b = v[i][j].ND; printf("%d %d v ",num, b); } printf(")\n"); } } vector<bool> curWart; LL ans = 0; bool spelniaLit(int pos, bool neg) { if(neg && !curWart[pos]) return true; if(!neg && curWart[pos]) return true; return false; } bool spelniaNaw(int nr) { REP(i, v[nr].size()) { if(spelniaLit(v[nr][i].ST-1, v[nr][i].ND)) return true; } return false; } bool spelnia() { REP(i, v.size()){ if(!spelniaNaw(i)) return false; } return true; } void rec(int pos) { REP(i, 2) { // cout << pos << " "; curWart[pos] = i; if(pos == (int)curWart.size() - 1) { if(spelnia()) ans = (ans+1) % MOD; } else rec(pos+1); } } void solve() { // printOut(); curWart = vector<bool>(n, false); rec(0); printf("%lld\n", ans); } void zeruj() { v.clear(); curWart.clear(); } int main() { // ios_base::sync_with_stdio(0); // cin >> test; REP(i, test) { zeruj(); readIn(); solve(); } 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | //parse test #include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define ST first #define ND second #define MP make_pair #define PB push_back typedef vector<int> VI; typedef pair<int, int> PI; typedef vector<PI> VPII; typedef set<int> SI; typedef long long LL; #ifdef DEBUG const bool debug = true; #else const bool debug = false; #endif int n, m, k, l, test = 1; const int INF = 1000 * 1000 * 1000; const int MAKSN = 1000 * 1000 + 13; // UZUPElnic const LL MOD = INF + 7; // nr, czy negacja vector<vector<pair<int, bool> > > v; void parseLine(); void parseBracket(); void readIn() { l = scanf("%d", &n); parseLine(); } void parseLine() { char c; l = scanf("%c",&c); // '\n' while (true) { l = scanf("%c", &c); if (c == '\n') return; if (c == '(') parseBracket(); } } int parseX() { int temp; l = scanf("%d", &temp); return temp; } void parseBracket() { vector<pair<int, bool> > temp; char c ='0'; int num; bool krulBul; // printf("Tag\n"/); // printf("("); while(true) { l = scanf("%c", &c); // printf("%c",c); krulBul = false; if(c == '~') { krulBul = true; l = scanf("%c", &c); //x // printf("%c",c); } if(c == 'x') { num = parseX(); // printf("%d ", num); temp.PB(MP(num, krulBul)); } if(c == ')') break; // printf( "\n"); } // printf("temp %d \n", (int)temp.size()); v.PB(temp); } void printOut() { REP(i, v.size()) { printf("("); REP(j, v[i].size()) { int num; bool b; num = v[i][j].ST; b = v[i][j].ND; printf("%d %d v ",num, b); } printf(")\n"); } } vector<bool> curWart; LL ans = 0; bool spelniaLit(int pos, bool neg) { if(neg && !curWart[pos]) return true; if(!neg && curWart[pos]) return true; return false; } bool spelniaNaw(int nr) { REP(i, v[nr].size()) { if(spelniaLit(v[nr][i].ST-1, v[nr][i].ND)) return true; } return false; } bool spelnia() { REP(i, v.size()){ if(!spelniaNaw(i)) return false; } return true; } void rec(int pos) { REP(i, 2) { // cout << pos << " "; curWart[pos] = i; if(pos == (int)curWart.size() - 1) { if(spelnia()) ans = (ans+1) % MOD; } else rec(pos+1); } } void solve() { // printOut(); curWart = vector<bool>(n, false); rec(0); printf("%lld\n", ans); } void zeruj() { v.clear(); curWart.clear(); } int main() { // ios_base::sync_with_stdio(0); // cin >> test; REP(i, test) { zeruj(); readIn(); solve(); } return 0; } |