poj2752 Seek the Name, Seek the Fame(kmp)
2017-07-28 22:26
351 查看
从len开始,每一个fail[len]都可以。。不过要倒着输出。。
#include <cstdio> #include <cstring> #define N 400010 char s ; int fail ,ans ; inline void getfail(char *t,int m){ int k=0;fail[1]=0; for(int i=2;i<=m;++i){ while(k&&t[k+1]!=t[i]) k=fail[k]; if(t[k+1]==t[i]) ++k; fail[i]=k; } } int main(){ // freopen("a.in","r",stdin); while(~scanf("%s",s+1)){ int len=strlen(s+1);int tot=0; getfail(s,len);int k=len; while(k) ans[++tot]=k,k=fail[k]; for(int i=tot;i>=1;--i) printf("%d ",ans[i]);puts(""); } return 0; }
相关文章推荐
- [poj2752]Seek the Name, Seek the Fame(KMP)
- [poj2752]Seek the Name, Seek the Fame_KMP
- POJ2752 Seek the Name, Seek the Fame 【KMP】
- 【poj2752】Seek the Name, Seek the Fame KMP
- 【KMP】POJ2752 Seek the Name, Seek the Fame
- 【POJ2752】Seek the Name, Seek the Fame(KMP)
- 【poj2752】Seek the Name, Seek the Fame kmp
- 【POJ2752】【KMP】Seek the Name, Seek the Fame
- POJ2752 Seek the Name, Seek the Fame(kmp)
- Seek the Name, Seek the Fame---poj2752(kmp中的Next数组)
- POJ2752 Seek the Name, Seek the Fame 【KMP】
- 【POJ2752】Seek the Name, Seek the Fame-KMP思想
- POJ 2752 Seek the Name, Seek the Fame KMP题解
- POJ2752 Seek the Name, Seek the Fame(KMP)
- POJ2752 - Seek the Name, Seek the Fame(KMP)
- poj 2752 Seek the Name, Seek the Fame(KMP应用)
- POJ 2752-Seek the Name, Seek the Fame(KMP的next数组运用)
- poj 2752 Seek the Name, Seek the Fame【KMP】
- POJ 2752 Seek the Name, Seek the Fame(KMP)
- POJ 2752 Seek the Name, Seek the Fame (KMP)