Target Regex: (100+1+|01)+
https://www.acmicpc.net/problem/1013
1. Regex to NFA (using mcnaughotn yamada thomspson construction algorithm)
2. e-clousre NFA to simplify dfa traslation
3. NFA to DFA using stacking
4. Optimize(Minimization) DFA
이제 이걸 그대로 코드로 옮기면
Answer:
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 | #include <iostream> using namespace std; int dfa[2][9] = { 2,3,-1,5,2,5,2,8,5, 1,-1,4,-1,1,6,7,7,4 }; int main() { int t; cin >> t; while ( t-- ) { char s[201]; cin >> s; int f = 0; for (int i = 0; s[i]; i++) if ((f = dfa[s[i] - '0'][f]) == -1) break; if (f == 4 || f == 6 || f == 7) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } | cs |
ㅇㅇ
와 백준에 오토마타도 나오는구나ㄷㄷ - dc App