Machine Learning
Time limit2sMemory limit1024 MB
Given every binary word up to length n marked accept or reject, build a DFA with the fewest states that matches all the marks.
- Level
Hard9 of 10
- Topics
- Backtracking, Trie, String
- Solved
- No attempts yet
Statement
Machine learning is a branch of theoretical computer science that studies what algorithms and computer programs can learn from training examples. In this problem you implement the simplest form of machine learning: train a deterministic finite automaton so that it correctly recognizes the words of a given set.
Formally, a deterministic finite automaton is a tuple , where is the finite input alphabet (here ), is a finite set of states, is the initial state, is the set of accepting states, and is the transition function.
The input to the automaton is a word over . Initially the automaton is in state . At each step it reads the next symbol of the input and moves from its current state to . After the whole word is processed, if the automaton is in an accepting state, it accepts . Otherwise it rejects .
Split all words of length from 0 to a given number into two sets, and . An automaton matches this split if it accepts every word in and rejects every word in . Words longer than may be either accepted or rejected.
Build an automaton that matches the given split and has the minimum possible number of states.
Input
The first line contains an integer (). The next lines describe and . Each line contains one word preceded by + if the word is in , or by - if it is in . Words are sorted by length, and words of equal length are sorted lexicographically.
Output
The first line contains (), the minimum number of states, and , the number of the initial state. States are numbered from 1 to .
The second line contains , the number of accepting states, followed by the numbers of the accepting states.
Then lines follow. The -th line contains and , separated by a space.