题解:

和上一题差不多

每个点记录前面的到这个点的最大值

初值赋为len[i]

然后注意要用子节点更新父节点

代码:

#include <bits/stdc++.h>
#define ll long long
#define rint register int
#define rep(i,h,t) for (rint i=h;i<=t;i++)
#define dep(i,t,h) for (rint i=t;i>=h;i--)
#define me(x) memset(x,0,sizeof(x))
using namespace std;
const int N=3e6;
const int INF=1e9;
char s[N];
int size[N],len[N],ch[N][];
int lst=,node=,t[N],a[N],fa[N],ans[N],ans2[N],num[N];
void extend(int c)
{
int f=lst,p=++node; lst=p;
len[p]=len[f]+; size[p]=;
while (f&&!ch[f][c]) ch[f][c]=p,f=fa[f];
if (!f) { fa[p]=; return;};
int x=ch[f][c],y=++node;
if (len[f]+==len[x]) {fa[p]=x; node--;return;};
len[y]=len[f]+; fa[y]=fa[x]; fa[x]=fa[p]=y;
memcpy(ch[y],ch[x],sizeof(ch[x]));
while (f&&ch[f][c]==x) ch[f][c]=y,f=fa[f];
}
void js()
{
int l=strlen(s),now=,t=;
rep(i,,l)
{
int x=s[i-]-'a';
if (ch[now][x]) now=ch[now][x],++t;
else
{
while (now&&!ch[now][x]) now=fa[now];
if (!now) now=,t=;
else t=len[now]+,now=ch[now][x];
}
ans[now]=max(ans[now],t);
}
}
int main()
{
freopen("1.in","r",stdin);
freopen("1.out","w",stdout);
ios::sync_with_stdio(false);
cin>>s;
int l=strlen(s);
rep(i,,l) extend(s[i-]-'a');
rep(i,,node) t[len[i]]++;
rep(i,,node) t[i]+=t[i-];
rep(i,,node) a[t[len[i]]--]=i;
rep(i,,N-) ans2[i]=len[i];
while (cin>>s)
{
me(ans);
js();
dep(i,node,)
{
int x=a[i];
ans2[x]=min(ans2[x],ans[x]);
ans[fa[x]]=max(ans[fa[x]],ans[x]);
}
}
int maxn=;
rep(i,,node) maxn=max(maxn,ans2[i]);
cout<<maxn<<endl;
return ;
}

SPOJ 1812 LCS2的更多相关文章

  1. spoj 1812 LCS2 - Longest Common Substring II (后缀自己主动机)

    spoj 1812 LCS2 - Longest Common Substring II 题意: 给出最多n个字符串A[1], ..., A[n], 求这n个字符串的最长公共子串. 限制: 1 < ...

  2. spoj 1812 LCS2(SAM+DP)

    [题目链接] http://www.spoj.com/problems/LCS2/en/ [题意] 求若干个串的最长公共子串. [思路] SAM+DP 先拿个串建个SAM,然后用后面的串匹配,每次将所 ...

  3. SPOJ 1812 LCS2 [后缀自动机 DP]

    题意: 求多个串<=10的最长连续子串 一个串建SAM,然后其他串在上面走 每个状态记录所有串在这个状态的公共子串的最小值 一个串在上面走的时候记录与每个状态公共子串的最大值,注意出现次数向父亲 ...

  4. SPOJ 1812 LCS2 - Longest Common Substring II

    思路 后缀自动机求多串的最长公共子串 对第一个建出后缀自动机,其他的在SAM上匹配,更新到一个节点的匹配长度最大值即可,最后对所有最大值取min得到一个节点的答案,对所有节点答案求max即可 然后注意 ...

  5. SPOJ.1812.LCS2(后缀自动机)

    题目链接 \(Description\) 求最多10个串的LCS(最长公共子序列). \(Solution\) 类比上题,对一个串建SAM,我们可以逐串地求出其在每个节点所能匹配的最大长度mx[i]. ...

  6. 【刷题】SPOJ 1812 LCS2 - Longest Common Substring II

    A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...

  7. SPOJ 1812 LCS2 - Longest Common Substring II (后缀自动机、状压DP)

    手动博客搬家: 本文发表于20181217 23:54:35, 原地址https://blog.csdn.net/suncongbo/article/details/85058680 人生第一道后缀自 ...

  8. spoj 1812 lcsII (后缀自动机)

    spoj 1812 lcsII (后缀自动机) 题意:求多个串的lcs,最多10个串,每个串最长10w 解题思路:后缀自动机.先建好第一个串的sam,然后后面的串拿上去跑(这个过程同前一题).sam上 ...

  9. SPOJ 1812 Longest Common Substring II(后缀自动机)(LCS2)

    A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...

随机推荐

  1. mongodb管理与安全认证

    mongodb数据管理 数据的导出.数据导入数据导出 mongoexport [使用mongoexport -h查看参数] 数据导入 mongoimport [使用mongoimport -h查看参数 ...

  2. 题解-SDOI2015 约数个数和

    Problem bzoj3994 洛谷3327 题意:设 \(d(x)\) 为 \(x\) 的约数个数,给定 \(N,M\),求\(\sum_{i=1}^N\sum_{j=1}^Md(ij)\) \( ...

  3. less个人学习笔记

    less中文官网:http://lesscss.cn/ . http://www.bootcss.com/p/lesscss/ Busy 视频教程:http://www.imooc.com/learn ...

  4. $Django 发送邮件--django封装模块和python内置SMTP模块

    一 使用SMTP模块发送邮件 import smtplib from email.mime.text import MIMEText from email.header import Header m ...

  5. Linux更新阿里源

    阿里云Linux安装镜像源地址:http://mirrors.aliyun.com/ CentOS系统更换软件安装源: 第一步:备份你的原镜像文件,以免出错后可以恢复. mv /etc/yum.rep ...

  6. Light OJ 1078

    题意: 给你 N,K 输出 KKKK.....KK能整除 N, 输出 K 的个数, (最小) 基础数学, 取摸运算即可. #include<bits/stdc++.h> using nam ...

  7. Laravel 怎么在 blade 视图中将带 HTML 字符原样输出

    ### 感觉这是比较细小的,细节处理问题,很容易就一下子想不起怎么处理 但知道处理方式是那么简单时,真的觉得基础不够扎实 ### 富文本编辑内容: 视图原样输出: 视图模板的标签是这样处理就可以的-- ...

  8. pipeline

    执行顺序:pipeline 写 pipeline类class Scrapyproject1Pipeline(object): def process_item(self, item, spider): ...

  9. 自定义redis连接池(字典操作)

    pool=redis.ConnectionPool(host='127.0.0.1', port=6379,max_connections=1000)conn=redis.Redis(connecti ...

  10. 【进阶3-4期】深度解析bind原理、使用场景及模拟实现(转)

    这是我在公众号(高级前端进阶)看到的文章,现在做笔记  https://github.com/yygmind/blog/issues/23 bind() bind() 方法会创建一个新函数,当这个新函 ...