题目大意:给你一个串让你求出重复次数最多的连续重复子串的重复次数。
解题思路:论文上给出的解答是:
这还没完,因为经过这两个点的情况还不完备,应还可以假设起点在 [ i*j-i+1, i*j-d],其中 d = i-L/i (d = i-L%i)其意义为根据已知的匹配长度,可以将起点往前移动的范围,太靠后将不能够构造出比之前更好的解。如果要求出某个最多的连续重复子串的最小字典序子需要枚举所有起点,但如果只是要的到最多的重复次数或者任意最多的连续重复子串,那么只需要枚举i*j-d处的起点即可,因为后面的起点若能够得到最优的结果,那么i*j-d处也一定能得到,且答案一样均为L/i+2。(这样保证了第0倍不是从起点开始的解的情况。)
SPOJ Problem Set (classical)687. RepeatsProblem code: REPEATS |
A string s is called an (k,l)-repeat if s is obtained by concatenating k>=1 times some seed string t with length l>=1. For example, the string
s = abaabaabaaba
is a (4,3)-repeat with t = aba as its seed string. That is, the seed string t is 3 characters long, and the whole string s is obtained by repeating t 4 times.
Write a program for the following task: Your