题目说给你一个长串,要你选一个最长子串,不包括任何一个给定串为子串。

建立一个自动机,每个点保存的信息为当前这个状态为结尾最长可以有多长?

然后。。。。就可以了。。。

#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_最长子串的更多相关文章

  1. [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 ...

  2. POJ 3294 Life Forms 后缀数组+二分 求至少k个字符串中包含的最长子串

    Life Forms   Description You may have wondered why most extraterrestrial life forms resemble humans, ...

  3. LeetCode: 3_Longest Substring Without Repeating Characters | 求没有重复字符的最长子串的长度 | Medium

    题目: Given a . For . 解题思路: 这个题让找一个字符串中具有不重复单词的最长子串的长度,如:ababc,子串为abc,长度为3.有这么几个方法: 方法一: 依赖字符串本身的一些特有函 ...

  4. [getLongestLength] 加和为0的最长子串长度

    点击这里查看原文 假设一个数组仅仅由1和-1组成,求该数组的和为0的最长子串的长度. 例如: {1,-1,1,-1,1,1,1} 输出:4. 昨天机试的时候做到这道题,不会做,今天思考一下. 普通的解 ...

  5. POJ-3294-Life Forms(后缀数组-不小于 k 个字符串中的最长子串)

    题意: 给定 n 个字符串,求出现在不小于 k 个字符串中的最长子串. 分析: 将 n 个字符串连起来,中间用不相同的且没有出现在字符串中的字符隔开,求后缀数组. 然后二分答案,将后缀分成若干组,判断 ...

  6. 求两个字符串最长子串的LCS算法 C语言实现(简短的实现函数)

    /************************************************************************* > File Name: lcs.c > ...

  7. Problem 2128 最长子串(kmp+strstr好题经典)

     Problem 2128 最长子串 Accept: 134    Submit: 523Time Limit: 3000 mSec    Memory Limit : 65536 KB  Probl ...

  8. fzu Problem 2128 最长子串(KMP + strstr 经典好题)

     Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长.  Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...

  9. SPOJ PHRASES 每个字符串至少出现两次且不重叠的最长子串

    Description You are the King of Byteland. Your agents have just intercepted a batch of encrypted ene ...

随机推荐

  1. ASCII, UNICODE, UTF-8, 字符集理解

    字符编码的发展历史 一个字节:最初一个字节的标准是混乱的,出现过4位.6位.7位的一字节标准,最终由于历史原因和物理存储需求(8位是2的3次方,方便物理存储),所以采用了8位为一个字节的标准. ASC ...

  2. Hibernate 3.0 HelloWorld

    说明 基于Hibernate 3.0,Mysql5.0,java jdk 1.7,运行需要的lib 库,从http://files.cnblogs.com/HCCZX/Hibernate_Lib.ra ...

  3. 可以用来求急的开源项目es5-shim

    最近发现一个JS库,无法在IE8中运行.比较纠结,又不想另找个库代替它,还好发现了这玩意.         它的作用:就给傻逼浏览器做兼容性,使得傻逼浏览器可以支持一些 es5 的 api       ...

  4. 【转载】D3DXVec3TransformNormal and D3DXVec3TransformCoord

    原文:D3DXVec3TransformNormal and D3DXVec3TransformCoord D3DXVec3TransformCoord 对向量进行变换,没啥好说明的,默认向量为行向量 ...

  5. day 4 名片管理系统 -函数版

    修改没有用函数的程序 具有独立功能的代码块 源程序 #1.打印功能信息 print("*"*50) print("\t名片管理系统 V3\t") print(& ...

  6. RegExp,实现匹配合法邮箱(英文邮箱)的正则表达式

    邮箱列表:@qq.com.@vip.qq.com.@foxmail.com,数字邮箱暂时不考虑 以下邮箱列表用于测试: lihaha@qq.com lihaha@vip.qq.com lihaha@f ...

  7. 面向忙碌开发者的 Android

    面向忙碌开发者的 Android passiontim 关注 2016.11.19 21:41* 字数 4013 阅读 2967评论 2喜欢 92 面向忙碌开发者的 Android 视频教程(Tuts ...

  8. ESP8266 NON-OS SDK 和 RTOS SDK实现GPIO中断不同点

    ESP8266 Non-OS SDK 和 RTOS SDK 实现GPIO的方法稍有不同: 对于 Non-OS SDK,比如需要把 MTDO 配置成输入,同时下降沿触发中断: gpio_init(voi ...

  9. python-python爬取妹子图片

    # -*- conding=utf-8 -*- import requests from bs4 import BeautifulSoup import io url = "https:// ...

  10. hdfs向hbase上传数据报错分析

    通过hbse的import工具向hbase导入文件时出现出错误: hbase org.apache.hadoop.hbase.mapreduce.Driver import hbase_rgrid_k ...