解题思路:
https://blog.csdn.net/eveee1123/article/details/113706481
详情
注意事项:
参考代码:
def KMP(s,p): s=' '+s p=' '+p n=len(s)-1 m=len(p)-1 match=[None for i in range(n+1)] ne=[0 for i in range(m+10)] j=0 for i in range(2,m+1): while(j and p[i]!=p[j+1]): j=ne[j] if p[i]==p[j+1]: j+=1 ne[i]=j j=0 for i in range(1,n+1): while(j and s[i]!=p[j+1]): j=ne[j] if s[i]==p[j+1]: j+=1 match[i]=j return match def init(st): tmp=[None for i in range((len(st)<i: p[i]=min(R-i,p[i_mirror]) else: p[i]=0 while(st[i+1+p[i]]==st[i-1-p[i]]): p[i]+=1 if i+p[i]>R: C=i R=i+p[i] return p s=input() dp=[0 for i in range(len(s)+10)] tail=[0 for i in range(len(s)+10)] p=manacher(init(s)) re_s=list(s);re_s.reverse() re_s=''.join(re_s) f=KMP(s,re_s) for i in range(1,len(s)+1): if dp[i-1]ans: final=[] ans=2*pre_suf+p[center] if pre_suf: final.append((tail[i-R]-pre_suf+1,pre_suf)) final.append((i-R+1,p[center])) if pre_suf: final.append((len(s)-pre_suf+1,pre_suf)) print(len(final)) for i in final: print(i[0],i[1])
0.0分
0 人评分
【明明的随机数】 (C++代码)浏览:827 |
不容易系列 (C语言代码)浏览:699 |
简单的a+b (C++语言代码)浏览:889 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:720 |
WU-陶陶摘苹果2 (C++代码)浏览:1011 |
C语言程序设计教程(第三版)课后习题6.6 (C语言代码)浏览:360 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:583 |
简单的a+b (C语言代码)浏览:570 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:565 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:651 |