POJ - 2406 Power Strings (后缀数组 最大重复次数)

Power Strings

 

Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).

Input

Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.

Output

For each s you should print the largest n such that s = a^n for some string a.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
3

Hint

This problem has huge input, use scanf instead of cin to avoid time limit exceed.

题目链接:http://poj.org/problem?id=2406

题目大意:给出一个字符串L是一个连续重复串,问最大重复次数是多少

思路:字符串L是由子串S重复R次得到的,枚举S的长度k,判断S是否满足条件。首先判断L的长度是否能被S的长度k整除,再看suffix(1)和suffix(k+1)的LCP是否等于n-k。线性预处理出所有后缀与suffi(1)的LCP

代码:

#include
#include
#include
using namespace std;
#define ll long long
#define F(x) ((x)/3+((x)%3==1?0:tb))
#define G(x) ((x)=0;i--) b[--wss[wv[i]]]=a[i];
}
void dc3(int *r,int *sa,int n,int m)
{
    int i,j,*rn=r+n,*san=sa+n,ta=0,tb=(n+1)/3,tbc=0,p;
    r[n]=r[n+1]=0;
    for(i=0;i=2;i--) b[i-1]=min(b[i],h[i]);
        for(int i=x+1;i<=n;i++) b[i]=min(b[i-1],h[i]);
        int ans=0;
        for(int i=1;i

 

你可能感兴趣的:(后缀数组,后缀自动机)