Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 如何将KMP算法应用于字符串问题,如http://www.spoj.com/problems/PERIOD/?_String_Algorithm_Data Structures_Substring_Computer Science - Fatal编程技术网

String 如何将KMP算法应用于字符串问题,如http://www.spoj.com/problems/PERIOD/?

String 如何将KMP算法应用于字符串问题,如http://www.spoj.com/problems/PERIOD/?,string,algorithm,data-structures,substring,computer-science,String,Algorithm,Data Structures,Substring,Computer Science,我已经学会了KMP算法,但在字符串问题中没有实现它。 有人能建议我如何使用KMP算法在SPOJ中解决上述问题吗? 链接:让我们假设长度为i的前缀的前缀函数是p[i]。 如果i mod i-p[i]==0,那么K=i/i-p[i],否则K=1证明的思想是任何周期都是最小周期的乘积,最小周期正好是i-p[i]。 因此,您可以使用KMP算法为字符串的所有前缀计算前缀函数,然后使用上面的公式

我已经学会了KMP算法,但在字符串问题中没有实现它。 有人能建议我如何使用KMP算法在SPOJ中解决上述问题吗?
链接:

让我们假设长度为i的前缀的前缀函数是p[i]。 如果i mod i-p[i]==0,那么K=i/i-p[i],否则K=1证明的思想是任何周期都是最小周期的乘积,最小周期正好是i-p[i]。 因此,您可以使用KMP算法为字符串的所有前缀计算前缀函数,然后使用上面的公式