1
+ #include < iostream>
2
+ #include < stdio.h>
3
+ #include < set>
4
+
5
+ using namespace std ;
6
+
7
+ char alphabet[256 ];
8
+ set<int > final_states;
9
+
10
+ bool isFinal (unsigned int num)
11
+ {
12
+ unsigned int check=1 ;
13
+ for (int j=0 ; j < 32 ; j++)
14
+ {
15
+ if ( num & check )
16
+ if ( final_states.find (j) != final_states.end () )
17
+ return true ;
18
+ check <<= 1 ;
19
+ }
20
+ return false ;
21
+ }
22
+
23
+ unsigned int addstate (unsigned int state, int pos)
24
+ {
25
+ int x=1 ;
26
+ for (int i=0 ; i<pos-1 ; i++)
27
+ x = x << 1 ;
28
+ return state | x;
29
+ }
30
+
31
+ int main ()
32
+ {
33
+ freopen (" input.in" , " r" , stdin);
34
+ int asize;
35
+ cin >> asize;
36
+ cout << asize<<endl;
37
+ char myalphabet;
38
+ for (int i=0 ; i<asize ; i++)
39
+ {
40
+ cin >> myalphabet;
41
+ alphabet[myalphabet] = 1 ;
42
+ cout << myalphabet << endl;
43
+ }
44
+ int n;
45
+ cin >> n;
46
+ int total_states = 1 << n;
47
+ int table[total_states][asize];
48
+ cout << n << " " << total_states;
49
+ for (unsigned int i=0 ; i<n ; i++ )
50
+ {
51
+ for (int j=0 ; j< 256 ; j++ )
52
+ {
53
+ if ( not alphabet[j] )
54
+ continue ;
55
+
56
+ int to_states;
57
+ cin >> to_states;
58
+ unsigned int state = 0 ;
59
+ for (int k=0 ; k<to_states ; k++)
60
+ {
61
+ int mystate;
62
+ cin >> mystate;
63
+ state = addstate (state, mystate);
64
+ }
65
+ table[1 <<i][j] = state;
66
+ }
67
+ }
68
+
69
+ for (unsigned int i=0 ; i< 1 <<n ; i++)
70
+ {
71
+ unsigned int current = i;
72
+
73
+ for (int j=0 ; j<256 ; j++ )
74
+ {
75
+ if ( not alphabet[j] )
76
+ continue ;
77
+ int check=1 ;
78
+ for (int k=0 ; k<32 ; k++)
79
+ {
80
+ if ( check & current )
81
+ {
82
+ unsigned int reachable = table[k][j];
83
+ table[current][j] |= reachable;
84
+ }
85
+ check <<= 1 ;
86
+ }
87
+ }
88
+ }
89
+
90
+ int final_size;
91
+ cin >> final_size;
92
+ for (int i=0 ; i<final_size ; i++)
93
+ {
94
+ int fstate;
95
+ cin >> fstate;
96
+ final_states.insert (fstate);
97
+ }
98
+
99
+ string s;
100
+ cin >> s;
101
+
102
+ }
0 commit comments