Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. Smallest Cyclic Shift to obtain lexicographical smallest of All possible:
- Consider,
- string "aba" then the minimum cyclic shift is 1 because by shifting the pattern
- by one we get "aab" which is lexicographically smallest of all possible ("aba",
- "aab", "baa"). For solving this problem we build the suffix automaton of
- "String + String". Now the problem is reduced to above problem where k = 1,
- solving until we get substring of length = length of given string.
- string ans;
- int t;
- int minShift(int ver, int tp=0)
- {
- if (tp==t)
- return st[ver].link;
- for (auto it : st[ver].next)
- {
- ans += it.ff;
- return minShift(it.ss, tp+1);
- }
- }
- minShift = length(s) - minShift.
- ans = lexicographically shortest string
- Practice Problem:
- UVA : 1584 - Circular Sequence
- UVA : 1314 - Hidden Password
- UVA : 719 - Glass Beads
Add Comment
Please, Sign In to add comment