The meaning of the question is hard to understand...
The finite state automation DFA is such an ordered group <Σ, U, S, T, Phi>; Σ represents the input Character Set, indicating the work scope of the automation; U represents all the State sets; S is the initial state; t is the final state; Phi represents the transfer function, defined as Phi: U × Σ → u.
Using DFA for string recognition requires you to do the following: the input of the automation is the string α over Σ. initially the automation is in State S. each step it reads the first character C of the input string and changes its state to Phi (u, c) Where U is the current state. after that the first character of the input string is removed and the step repeats. if when its input string is empty the automation is in the terminal state, it is said that it accepts the initial string α, in the other case it rejects it.
Then the bored author adds a nonabsorbing edges to him. The literal translation does not absorb edges. Define Function x: u x Σ → {0, 1 }. when making a transition from some state u with some character C, the leading character is removed from the input string only if x (u, c) = 0. if X (u, c) = 1, the input string is kept intact and next transition is Med with the new State and the same character.
This DFA is called nadfa.
The conditions for nadfa to accept strings are: Such automation accepts some string α if after a number of steps it transits to the terminal state and the input string becomes empty.
Input: the first line is character set Σ. The next row is K, indicating the number of states. The first digit s in the next row represents the initial state, the second digit l represents the number of the ending state, and then the number l represents the number of the ending state. Then a matrix of K * | Σ | represents the function Phi. Then a matrix of the same size represents Function x. N.
This is the question that you want to be able to accept. In the form of B, the number of strings accepted by DFA (nadfa) is N.
It turned out to be question a of ASC #2 !!!
Then we found that sgu200 ~ 2 ** is the original question of ASC .. Can't bear to look straight .. In my opinion, sgu cannot be used ..
However, sgu200 is the answer! Bzoj is used to train some algorithms.
How ??
DP is obvious. F [I] [J] indicates the number of strings in the status J when I is matched. Because of the existence of non-absorbent edges, you can use the memory to search for direct transfer of pre-processing states.
High precision... Great pressure position...
1 //{HEADS 2 #define FILE_IN_OUT 3 #include <cstdio> 4 #include <cstring> 5 #include <cstdlib> 6 #include <cmath> 7 #include <ctime> 8 #include <algorithm> 9 #include <iostream> 10 #include <fstream> 11 #include <vector> 12 #include <stack> 13 #include <queue> 14 #include <deque> 15 #include <map> 16 #include <set> 17 #include <bitset> 18 #include <complex> 19 #include <string> 20 #define REP(i, j) for (int i = 1; i <= j; ++i) 21 #define REPI(i, j, k) for (int i = j; i <= k; ++i) 22 #define REPD(i, j) for (int i = j; 0 < i; --i) 23 #define STLR(i, con) for (int i = 0, sz = con.size(); i < sz; ++i) 24 #define STLRD(i, con) for (int i = con.size() - 1; 0 <= i; --i) 25 #define CLR(s) memset(s, 0, sizeof s) 26 #define SET(s, v) memset(s, v, sizeof s) 27 #define mp make_pair 28 #define pb push_back 29 #define PL(k, n) for (int i = 1; i <= n; ++i) { cout << k[i] << ‘ ‘; } cout << endl 30 #define PS(k) STLR(i, k) { cout << k[i] << ‘ ‘; } cout << endl 31 using namespace std; 32 void FILE_INIT(string FILE_NAME) { 33 #ifdef FILE_IN_OUT 34 #ifndef ONLINE_JUDGE 35 freopen((FILE_NAME + ".in").c_str(), "r", stdin); 36 freopen((FILE_NAME + ".out").c_str(), "w", stdout); 37 #endif 38 #endif 39 } 40 typedef long long LL; 41 typedef double DB; 42 typedef pair<int, int> i_pair; 43 const int INF = 0x3f3f3f3f; 44 //} 45 46 const int maxn = 1000 + 10; 47 const int maxl = 100 + 10; 48 const int maxm = 60 + 5; 49 const int maxc = 27; 50 const int base = 1000000000; 51 52 char sigma[maxc]; 53 int Snum, Size, S, k, L, n; 54 int teminal_state[maxn], phi[maxn][maxc], chi[maxn][maxc], trans[maxn][maxc]; 55 56 struct big_int { 57 int d[maxl]; 58 int len; 59 big_int() { 60 CLR(d); 61 len = 1; 62 } 63 big_int &operator += (const big_int &a) { 64 len = max(len, a.len); 65 REP(i, len) { 66 d[i] += a.d[i]; 67 if(base < d[i]) { 68 d[i + 1] += d[i] / base; 69 d[i] %= base; 70 } 71 } 72 for(; 0 < d[1 + len]; ++len); 73 return *this; 74 } 75 void print() { 76 printf("%d", d[len]); 77 for(int i = len - 1; 0 < i; --i) { 78 printf("%09d", d[i]); 79 } 80 puts(""); 81 } 82 }f[maxn][maxm]; 83 84 void dfs(int u, int c) { 85 if(chi[u][c] == 0) { 86 trans[u][c] = u; 87 } 88 if(trans[u][c]) { 89 return; 90 } 91 trans[u][c] = -1; 92 dfs(phi[u][c], c); 93 trans[u][c] = trans[phi[u][c]][c]; 94 } 95 96 int main() { 97 FILE_INIT("201"); 98 99 scanf("%s", sigma);100 Size = strlen(sigma);101 scanf("%d", &k);102 scanf("%d %d", &S, &L);103 REP(i, L) {104 scanf("%d", &teminal_state[i]);105 }106 REP(i, k) {107 REP(j, Size) {108 scanf("%d", &phi[i][j]);109 }110 }111 REP(i, k) {112 REP(j, Size) {113 scanf("%d", &chi[i][j]);114 }115 }116 scanf("%d", &n);117 REP(i, k) {118 REP(j, Size) {119 if(!trans[i][j]) {120 dfs(i, j);121 }122 }123 }124 f[S][0].d[1] = 1;125 REPI(i, 0, n - 1) {126 REP(j, k) {127 REP(c, Size) {128 if(trans[j][c] > 0) {129 f[phi[trans[j][c]][c]][i + 1] += f[j][i];130 }131 }132 }133 }134 big_int ans;135 REP(i, L) {136 ans += f[teminal_state[i]][n];137 }138 ans.print();139 140 return 0;141 }
View code