hdu-4763 kmp next数组的应用

http://acm.hdu.edu.cn/showproblem.php?pid=4763

求最长的三个不重叠公共前缀,要求EAEBE的格式  即要求第一个在字符串开头  第三个在末尾  中间不能和首尾重叠

刚开始就往后缀数组想  想了好久发现时间复杂度不可能呀  然后就想起了以前poj上水过的一题

http://blog.csdn.net/fire_cat11211022/article/details/9974631

就是利用kmp next数组的特性求解  然后就是自己找的规律 自己都说不清楚  囧

代码如下

#include 
#include 
#include 
#define max 1000010
using namespace std;
int n[max];
char str1[max];
int next(char s[])
{
    n[0]=-1;
    int j=0,k=-1;
    int len=strlen(s);
    int LL=len;
    while(j


你可能感兴趣的:(hdu)