zoukankan      html  css  js  c++  java
  • bzoj3676: [Apio2014]回文串

    放板子

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    typedef long long LL;
    const int _=1e2;
    const int maxn=3*1e5+_;
    
    struct Pnode{int w[30],fail,len;};
    struct PAM
    {
        int n,a[maxn];char ss[maxn];
        Pnode ch[maxn];int cnt,last,num[maxn];
        void insert(int k,int x)
        {
            int pre=last;
            while(a[k]!=a[k-ch[pre].len-1])pre=ch[pre].fail;
            if(ch[pre].w[x]==0)
            {
                int now=++cnt;
                ch[now].len=ch[pre].len+2;
                int ppre=ch[pre].fail;
                while(a[k]!=a[k-ch[ppre].len-1])ppre=ch[ppre].fail;
                ch[now].fail=ch[ppre].w[x];
                ch[pre].w[x]=now;
                
            }
            last=ch[pre].w[x];
            num[last]++;
        }
        void init()
        {
            cnt=1,last=0;
            ch[0].len=0,ch[1].len=-1;
            ch[0].fail=1,ch[1].fail=0;
        }
        void solve()
        {
            init();
            for(int i=1;i<=n;i++)
            insert(i,a[i]);
            for(int i=cnt;i>=2;i--)num[ch[i].fail]+=num[i];
            
            LL ans=0;
            for(int i=2;i<=cnt;i++)ans=max(ans,(LL)num[i]*ch[i].len);
            printf("%lld
    ",ans);
        }
        void main()
        {
            scanf("%s",ss+1);n=strlen(ss+1);
            for(int i=1;i<=n;i++)a[i]=ss[i]-'a'+1;
            solve();
        }
    }P;
    
    int main()
    {
        P.main();
        return 0;
    }
  • 相关阅读:
    Zuul
    熔断机制
    跨域问题
    过滤器
    从Ftp下载某一文件夹下的所有文件(三)
    java操作Ftp文件的一些方式(一)
    Java代码实现FTP单个文件下载(二)
    一些order
    Spring Boot
    利用dubbo服务对传统工程的改造
  • 原文地址:https://www.cnblogs.com/AKCqhzdy/p/10488169.html
Copyright © 2011-2022 走看看