FZU2128_最长子串
题目说给你一个长串,要你选一个最长子串,不包括任何一个给定串为子串。
建立一个自动机,每个点保存的信息为当前这个状态为结尾最长可以有多长?
然后。。。。就可以了。。。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define maxn 1000100
#define inf 99999999
using namespace std; char s0[maxn];
char s[];
int next[][],fail[],tag[],N;
int n,m,f[maxn],ans; int add()
{
N++;
for (int i=; i<; i++) next[N][i]=;
tag[N]=inf;
fail[N]=;
return N;
} void init()
{
N=-;
N=add();
} void insert()
{
int cur=,tep;
for (int i=; s[i]; i++)
{
tep=s[i]-'a';
if (next[cur][tep]==) next[cur][tep]=add();
cur=next[cur][tep];
}
tag[cur]=strlen(s);
} void AC_build()
{
int cur,child;
queue<int> Q;
Q.push();
while (!Q.empty())
{
cur=Q.front(),Q.pop();
for (int i=; i<; i++)
{
child=next[cur][i];
if (child)
{
Q.push(child);
if (cur==) fail[child]=;
else fail[child]=next[fail[cur]][i];
tag[child]=min(tag[child],tag[fail[child]]);
}
else next[cur][i]=next[fail[cur]][i];
}
}
} void query()
{
ans=;
f[]=;
int cur=,tep;
for (int i=; s0[i]; i++)
{
f[i]=f[i-]+;
tep=s0[i]-'a';
cur=next[cur][tep];
f[i]=min(f[i],tag[cur]);
ans=max(ans,f[i]);
}
} int main()
{
while (scanf("%s",s0+)!=EOF)
{
init();
scanf("%d",&n);
while (n--)
{
scanf("%s",s);
insert();
}
AC_build();
query();
printf("%d\n",ans-);
}
return ;
}
FZU2128_最长子串的更多相关文章
- [LeetCode] Longest Substring with At Most Two Distinct Characters 最多有两个不同字符的最长子串
Given a string S, find the length of the longest substring T that contains at most two distinct char ...
- POJ 3294 Life Forms 后缀数组+二分 求至少k个字符串中包含的最长子串
Life Forms Description You may have wondered why most extraterrestrial life forms resemble humans, ...
- LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium
题目: Given a . For . 解题思路: 这个题让找一个字符串中具有不重复单词的最长子串的长度,如:ababc,子串为abc,长度为3.有这么几个方法: 方法一: 依赖字符串本身的一些特有函 ...
- [getLongestLength] 加和为0的最长子串长度
点击这里查看原文 假设一个数组仅仅由1和-1组成,求该数组的和为0的最长子串的长度. 例如: {1,-1,1,-1,1,1,1} 输出:4. 昨天机试的时候做到这道题,不会做,今天思考一下. 普通的解 ...
- POJ-3294-Life Forms(后缀数组-不小于 k 个字符串中的最长子串)
题意: 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. 分析: 将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组. 然后二分答案,将后缀分成若干组,判断 ...
- 求两个字符串最长子串的LCS算法 C语言实现(简短的实现函数)
/************************************************************************* > File Name: lcs.c > ...
- Problem 2128 最长子串(kmp+strstr好题经典)
Problem 2128 最长子串 Accept: 134 Submit: 523Time Limit: 3000 mSec Memory Limit : 65536 KB Probl ...
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- SPOJ PHRASES 每个字符串至少出现两次且不重叠的最长子串
Description You are the King of Byteland. Your agents have just intercepted a batch of encrypted ene ...
随机推荐
- 20155318 《Java程序设计》实验四 (Android程序设计)实验报告
20155318 <Java程序设计>实验四 (Android程序设计)实验报告 实验内容 基于Android Studio开发简单的Android应用并部署测试; 了解Android.组 ...
- echarts 去掉最外部边框
在option中,插入一下代码即可: grid: {show:'true',borderWidth:'0'}, 插入代码前: 插入代码后:
- 浅入tcp
1.认识TCP tcp协议是传输层协议,它的最主要的3个特点是面向连接.可靠保证.基于字节流.当应用层把数据给tcp层时,注意如果数据大于MSS是要在tcp层进行分段的.tcp协议为了保证不丢包会给每 ...
- eclipse 打包maven项目的坑
一.问题: 公司开发了一个项目,需要作为后台服务运行,整个项目的构成是:[maven + spring + eclipse] 在使用打包的时候遇到许多问题: (1)eclipse中maven工具的集成 ...
- Win SERVER 2008 许可证激活失败,系统重启问题
服务器系统win server2008 R2 SP1,频繁重启,查看日志 有显示 许可证激活(slui.exe)失败,错误代码如下:0x800401F9 和 Windows 许可证激活失败.错误 0x ...
- 【搜索好题】bzoj1501 [NOI2005]智慧珠游戏
bzoj1501 [NOI2005]智慧珠游戏 搜索苟逼题系列. 暴力枚举每一种情况(包括旋转翻转全都考虑在内)然后码出代码. (正解似乎不是这样子的) 那年好像还有平衡树苟逼题维护数列233333心 ...
- T-SQL语句基础
连接服务器 - 去哪个仓库找目标数据库 - 找仓库中的目标区域查找目标表 - 找货柜找数据(以行为基础单位) - 在货柜上找到目标的物品 基础T-Sql语句1.SQL语句的注释 2.创建数据库crea ...
- Supervisor4.0和python2.7的crit问题,导致python进程阻塞
1.问题原因 Supervisor高版本在守护python2.7的服务时,会crit并报错并倒至进程阻塞(python进程存在,但不在运行)的问题,一般会和字符集有关系 <type 'excep ...
- ubuntn 安装软件
安装输入法 一.Ctrl+Alt+T打开终端,输入sudo apt-get install fcitx,安装fcitx插件. 二.打开input method,选择fcitx. 三.打开system ...
- 牛客小白月赛9H论如何出一道水题(两个连续自然数互质)
题面 记录一下...连续得两个自然数互质,这题再特判一下1的情况 #include<bits/stdc++.h> using namespace std; int main() { lon ...