链接:
#include <stdio.h>
int main()
{
puts("转载请注明出处[vmurder]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/44960463");
}
题意:
题意同BZOJ3942,不过要删除的串是多串
http://blog.csdn.net/vmurder/article/details/44959895
题解:
……思路一模一样,除了不用kmp用AC自动机
代码:
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 101000
#define T 26
#define inf 0x3f3f3f3f
using namespace std;
char s[N];
struct Eli
{
int son[N][T],len[N],cnt;
char s[N];
void insert()
{
scanf("%s",s);
int i,x=0,alp;
for(i=0;s[i];i++)
{
alp=s[i]-‘a‘;
if(!son[x][alp])son[x][alp]=++cnt;
x=son[x][alp];
}
len[x]=max(len[x],i);
}
int fail[N];
void keep()
{
queue<int>q;
q.push(0);
int i,u,v;
while(!q.empty())
{
u=q.front(),q.pop();
len[u]=max(len[u],len[fail[u]]);
for(i=0;i<T;i++)
{
if(v=son[u][i])
{
if(!u)fail[v]=0;
else fail[v]=son[fail[u]][i];
q.push(v);
}
else son[u][i]=son[fail[u]][i];
}
}
}
}eli;
int f[N],stk[N],top;
int main()
{
freopen("test.in","r",stdin);
int i,n;
scanf("%s%d",s+1,&n);
while(n--)eli.insert();
eli.keep();
for(i=1;s[i];i++)
{
f[i]=eli.son[f[stk[top]]][s[i]-‘a‘];
stk[++top]=i;
top-=eli.len[f[i]];
}
for(i=1;i<=top;i++)printf("%c",s[stk[i]]);
return 0;
}
时间: 2024-10-07 19:36:16