题解:

和上一题差不多

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

初值赋为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. U3D虚拟摇杆制作

    来自https://www.cnblogs.com/jiuxuan/p/7453762.html 1.创建两个Image,修改第一个Image名称为 Background,把第二个Image放入 Ba ...

  2. 出现警告“user1 不在 sudoers 文件中。此事将被报告。”

    linux中不是每个用户都有sudo权限. 在/etc/下有个文件sudoers 由此文件可知只有用户为sudo这个组的成员之后才能执行sudo命令 此时,我们查看用户user1的属性: 由此看出us ...

  3. bzoj 1175: The stairways of Saharna

    一道杨氏矩阵的题,萌新初入门,还不是很懂,这篇 blog 讲的超级好(就是看图有点麻烦) 据说这玩意儿可以代替堆和平衡树用,支持插入.删除.查询,跑得还挺快的(慢着,复杂度好像是 n^2 ? 而且空间 ...

  4. live555运行时报错:StreamParser internal error ( 86451 + 64000 > 150000)

    搭建好live555服务器后,使用 vlc播放网络视频.此时服务器端报如下错误: StreamParser internal error ( 86451 + 64000   > 150000). ...

  5. maven项目板块的pom.xml配置

    项目名为helloweb 项目文件结构图1 helloweb>pom.xml内容如下: <project xmlns="http://maven.apache.org/POM/4 ...

  6. ebs 12.1.1打中文补丁

    环境变量设置 oracle 用户,应用env环境变量 . /u01/app/db/tech_st/11.1.0/PROD_erpapp1.env alias s='sqlplus / as sysdb ...

  7. 二、消息队列之如何在C#中使用RabbitMQ

    1.什么是RabbitMQ.详见 http://www.rabbitmq.com/. 作用就是提高系统的并发性,将一些不需要及时响应客户端且占用较多资源的操作,放入队列,再由另外一个线程,去异步处理这 ...

  8. python 初识函数

    1.什么是函数 函数就是对一个代码块 或者功能的封装,什么时候用,什么时候执行 语法: def  函数名():            函数体(代码块) 函数的调用 函数名()          #所有 ...

  9. Jmeter下载安装配置及使用(windows)

    1 前言 仅作为记录使用. 2 步骤 2.1 下载地址:http://jmeter.apache.org/download_jmeter.cgi 2.2 选择binary版本即可:apache-jme ...

  10. JS调用摄像头并上传图片到服务器

    本功能只能把图片转成base64码上传,如何上传图片还没有修改出来,有兴趣的朋友弄出来了,请给我留下言,谢谢了! 直接上代码,需要的朋友直接复制就可以使用了. <!DOCTYPE html> ...