轻量级前端框架助力开发者提升项目效率与性能
539
2022-10-29
poj 1961 Period(kmp最短循环节)
题目链接
Description
For each prefix of a given string S with N characters (each character has an ASCII code between 97 and 126, inclusive), we want to know whether the prefix is a periodic string. That is, for each i (2 <= i <= N) we want to know the largest K > 1 (if there is one) such that the prefix of S with length i can be written as A K ,that is A concatenated K times, for some string A. Of course, we also want to know the period K.……………………
题意:
给定一个长度为n的字符串s,求他每个前缀的最短循环节。换句话说,对于每个i(2<=i<=n),求一个最大的整数k(如果k存在),使得s的前i个字符可以组成的前缀是某个字符串重复k次得到的。输出所有存在K的i和对应的k。
这是刘汝佳《算法竞赛入门经典训练指南》上的原题(p213),用KMP构造状态转移表。
解题代码(完全参照白书):
//poj 1961#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~