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 ...
随机推荐
- 北京Uber优步司机奖励政策(4月14日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- eclipse中编译出现错误undefined reference to `_sbrk'
1. 在eclipse中使用gcc-arm-none-eabi-7-2017-q4-major-win32编译代码的时候出现了undefined reference to `_sbrk' e:/pro ...
- Android 7.1.1系统源码下载、编译、刷机-Nexus 6实战
想成为一位合格的Android程序员或者一位Android高级工程师是十分有必要知道Android的框架层的工作原理,要知道其工作原理那么就需要阅读Android的源代码. 想要阅读Android的源 ...
- scrapy (一)
scrapy框架 scrapy 是一个爬虫框架,能够高效率,高层次的爬取页面的数据并进行处理. 在scrapy的英文文档中,有这样的一个流程图 scrapy 框架主要分为五大部分,spider, en ...
- Sublime Text3添加右键
在Sublime Text3安装目录下新建一个文件 sublime_addright.inf 文件内容: [Version] Signature="$Windows NT$" [D ...
- fastdfs+nginx+image_filter安装与生成缩略图
fastdfs简介 类似google FS的一个轻量级分布式文件系统,纯C实现,支持linux.FreeBSD等UNIX系统: 只能通过API访问,不支持POXIS: 文件不分块存储,上传的文件和OS ...
- 阿里与ShopRunner达成协议 联手在国内推出服务
阿里巴巴集团与美国在线零售商 ShopRunner 达成协议,将帮助后者在中国大陆销售商品和履行订单交付产品. ShopRunner 首席战略官菲奥娜·迪亚斯(Fiona Dias)周三接受媒体采访时 ...
- python request 获取cookies value值的方法
import requests res = requests.get(url) cookies = requests.utils.dict_from_cookiejar(res.cookies) pr ...
- Sorting a Three-Valued Sequence(三值排序)
Description 排序是一种很频繁的计算任务.现在考虑最多只有三值的排序问题.一个实际的例子是,当我们给某项竞赛的优胜者按金银铜牌序的时候. 在这个任务中可能的值只有三种1,2和3.我们用交换的 ...
- scrum立会报告+燃尽图(第三周第一次)
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://coding.net/u/wuyy694 ...