forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1011NTA.cpp
More file actions
69 lines (64 loc) · 1.32 KB
/
1011NTA.cpp
File metadata and controls
69 lines (64 loc) · 1.32 KB
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
#include <iostream>
#include <string>
#include <strstream>
#include <vector>
#include <utility>
using namespace std;
vector<pair<int, int> > table[15][10];
char tree[4096];
int n, m, k, l;
int search(int p)
{
int l = 0, r = 0, sig = 0;
if (tree[p * 2 + 1] != '*') {
l = search(p * 2 + 1);
r = search(p * 2 + 2);
}
else for (int i = n - m; i < n; ++i) {
l |= 1 << i;
r |= 1 << i;
}
for (int i = 0; i < n; i++) {
vector<pair<int, int> > &t = table[i][tree[p] - 'a'];
for (int j = 0; j < t.size(); j++)
if ((1 << t[j].first & l) && (1 << t[j].second & r)) sig |= 1 << i;
}
return sig;
}
int main()
{
int nta = 0;
while (1) {
cin >> n >> m >> k;
if (!n && !m && !k) break;
cin >> ws;
if (nta) cout<<endl;
cout << "NTA" << ++nta << ":" << endl;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < k; ++j) {
table[i][j].clear();
string s;
getline(cin, s);
istrstream is(s.c_str());
while (1) {
int a, b;
is >> a >> b;
if (is.fail()) break;
table[i][j].push_back(make_pair(a, b));
}
}
}
while (1) {
memset(tree, '*', sizeof(tree));
int n;
cin >> l >> ws;
if (l < 0) break;
n = (1 << (l + 1)) - 1;
for (int i = 0; i < n; i++)
cin >> tree[i];
if (search(0) & 1) cout << "Valid" << endl;
else cout << "Invalid" << endl;
}
}
return 0;
}