[后缀自动机] POJ 1743 Musical Theme
来源:互联网 发布:linux 双网卡双网关 编辑:程序博客网 时间:2024/05/19 10:14
又一道男人八题哦
先差分 然后就是找出现两次的不相交的最大子串
考虑对于每个点 记录它的right集的最值 用差值和maxl的最小值更新答案
#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#define cl(x) memset(x,0,sizeof(x))using namespace std;inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; } return *p1++;}inline void read(int &x){ char c=nc(),b=1; for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1; for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;}const int N=20005;const int K=87<<1|1;struct state{ int len,link,next[K];}st[N<<1];int ncnt,last;int maxv[N<<1],minv[N<<1];inline void Extend(int c){ int cur=++ncnt,p; st[cur].len=st[last].len+1; maxv[cur]=minv[cur]=st[cur].len; for (p=last;p!=-1 && !st[p].next[c];p=st[p].link) st[p].next[c]=cur; if (p==-1) st[cur].link=0; else{ int q=st[p].next[c]; if (st[q].len==st[p].len+1) st[cur].link=q; else{ int nq=++ncnt; maxv[nq]=-1<<30; minv[nq]=1<<30; st[nq].len=st[p].len+1; st[nq].link=st[q].link; for (int i=0;i<K;i++) st[nq].next[i]=st[q].next[i]; for (;p!=-1 && st[p].next[c]==q;p=st[p].link) st[p].next[c]=nq; st[q].link=st[cur].link=nq; } } last=cur;}int tmp[N<<1],sum[N<<1];inline void Sort(){ for (int i=0;i<=ncnt;i++) sum[st[i].len]++; for (int i=1;i<=st[last].len;i++) sum[i]+=sum[i-1]; for (int i=0;i<=ncnt;i++) tmp[sum[st[i].len]--]=i;}int n,a[N];int main(){ freopen("t.in","r",stdin); freopen("t.out","w",stdout); while (1){ read(n); if (!n) break; for (int i=1;i<=n;i++) read(a[i]); for (int i=1;i<=n;i++) a[i]-=a[i+1]; for (int i=1;i<n;i++) a[i]+=87; st[0].link=-1; for (int i=1;i<n;i++) Extend(a[i]); Sort(); for (int i=ncnt+1;i;i--) if (tmp[i]){ maxv[st[tmp[i]].link]=max(maxv[st[tmp[i]].link],maxv[tmp[i]]); minv[st[tmp[i]].link]=min(minv[st[tmp[i]].link],minv[tmp[i]]); } int Ans=0; for (int i=1;i<=ncnt;i++){ int ret=min(maxv[i]-minv[i],st[i].len); if (ret>=4) Ans=max(Ans,ret+1); } printf("%d\n",Ans); ncnt=last=0; cl(st); cl(tmp); cl(sum); } return 0;}
0 0
- poj 1743 Musical Theme【后缀自动机】
- poj 1743 Musical Theme(后缀自动机)
- [后缀自动机] POJ 1743 Musical Theme
- poj 1743 Musical Theme 后缀数组
- POJ 1743 Musical Theme 后缀数组
- poj 1743 Musical Theme 【后缀数组】
- poj 1743 Musical Theme 后缀数组
- POJ 1743 Musical Theme(后缀数组)
- POJ 1743 Musical Theme(后缀数组)
- poj 1743 Musical Theme 后缀数组
- poj 1743 Musical Theme(后缀数组)
- POJ 1743 Musical Theme (后缀数组)
- 【后缀数组】 POJ 1743 Musical Theme
- 【POJ 1743】Musical Theme【后缀数组】
- POJ 1743 Musical Theme 后缀数组
- [后缀数组+二分] poj 1743 Musical Theme
- 【后缀数组】【poj 1743】Musical Theme
- 【POJ】1743 Musical Theme 【后缀数组】
- c++判断文件编码格式
- SPOJ-GSS7 Can you answer these queries VII(树上区间最大和)
- AsyncTask的源码分析,非常详细!
- Servlet之ServletContext创建对象和作用
- 12c Oracle_Home下的监听器监听11g数据库的问题
- [后缀自动机] POJ 1743 Musical Theme
- Android之旅第四站——Simpleapter的使用…
- 破坏性批评与建设性批评
- [后缀自动机 parent树] BZOJ 4566 [Haoi2016]找相同字符
- 艳辉网V2.0之采集系统
- 太姥山攻略
- 字典转换成模型属性代码笔记
- `uvm_component_utils
- 《深入理解java虚拟机》-虚拟机字节码执行引擎