[ural 1960] Palindromes and Super Abilities
2015-04-09 20:39
447 查看
继续练习模版。
回文树。。。
回文树。。。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int Maxn=100005; char S[Maxn]; int len[Maxn],ans[Maxn],fail[Maxn]; int son[Maxn][26],n,st,p,c,last,i,t; int newnode(int x){ len[st] = x; return st++; } void init(){ scanf("%s",S+1); n = strlen(S+1); S[0] = '#'; newnode( 0 ); newnode( -1 ); fail[0] = 1; } int get_fail(int x,int n){ while (S[n-len[x]-1]!=S ) x=fail[x]; return x; } int main(){ //freopen("ural.in","r",stdin); //freopen("ural.out","w",stdout); init(); for (i=1;i<=n;i++){ c = S[i]-'a'; t = get_fail(last,i); if (son[t][c]==0){ p = newnode( len[t]+2 ); fail[p] = son[get_fail( fail[t], i)][c]; son[t][c] = p; ans[i]=1; } last = son[t][c]; } for (i=1;i<=n;i++) ans[i]+=ans[i-1]; for (i=1;i<n;i++) printf("%d ",ans[i]); printf("%d\n",ans ); return 0; }
相关文章推荐
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
- URAL - 1960 Palindromes and Super Abilities
- 【URAL】1960. Palindromes and Super Abilities
- URAL 1960 Palindromes and Super Abilities (回文树)
- 【ural】1960. Palindromes and Super Abilities【Palindromic Tree】
- URAL 1960- Palindromes and Super Abilities (回文树)
- Ural1960 Palindromes and Super Abilities
- Ural 1960 Palindromes and Super Abilities
- Ural1960 Palindromes and Super Abilities
- URAL1960 Palindromes and Super Abilities
- URAL 1960 Palindromes and Super Abilities
- 【后缀回文自动机】 URAL 1960 Palindromes and Super Abilities
- ural 1960 Palindromes and Super Abilities 题解
- URAL1960-Palindromes and Super Abilities
- URAL 1960 Palindromes and Super Abilities (Palindromic Tree)
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
- URAL 2040 Palindromes and Super Abilities 2
- URAL 2040 Palindromes and Super Abilities 2(回文树)
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
- URAL 2040 Palindromes and Super Abilities 2(回文树)