如何用KMP算法求解POJ 1961 Period的最短循环节问题?

2026-06-11 15:1812阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计494个文字,预计阅读时间需要2分钟。

如何用KMP算法求解POJ 1961 Period的最短循环节问题?

题目链接:+Description+对于给定字符串S的每个长度为N的子串(每个字符的ASCII码在97到126之间,包含126),我们想知道这个子串是否是周期性的。也就是说,对于每个i(2≤i≤N),我们需要检查子串S[1:i]是否是周期性的。


​​题目链接​​

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。

阅读全文

本文共计494个文字,预计阅读时间需要2分钟。

如何用KMP算法求解POJ 1961 Period的最短循环节问题?

题目链接:+Description+对于给定字符串S的每个长度为N的子串(每个字符的ASCII码在97到126之间,包含126),我们想知道这个子串是否是周期性的。也就是说,对于每个i(2≤i≤N),我们需要检查子串S[1:i]是否是周期性的。


​​题目链接​​

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。

阅读全文