Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3. Finding lexicographically k'th smallest substring:
- The number of path / substring
- of a node / state of suffix automaton defines that we can obtain such number of
- substring which starts with the transitions. So, at first we calculate number of
- substring of all states and then do following:
- Let, there are two states which we can go from initial state. There can be two
- probabilities.
- 1. The number of substring from start(1) is less than k. So, we can be sure that
- our desired substring will not start with transition(1). So, we subtract
- that number of substring from k.
- 2. If the number is equal or greater then we go to these state and print the
- transition name. Then subtract 1 from k as we take 1 character. The process
- end when k is 0.
- void kLex(int ver, int k)
- {
- if (k == 0)
- return;
- for (auto it : st[ver].next)
- {
- int tSub = d[it.ss];
- if (tSub < k) // this state node belong
- {
- k -= tSub;
- }
- else
- {
- cout << it.ff;
- if (k == 1) cout << endl;
- kLex(it.ss, k-1);
- return; // do nothing when return
- }
- }
- }
- Practice Problem :
- Spoj : SUBLEX - Lexicographical Substring Search
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement