题目大意
解题思路
对非法串构ac自动机,对于l较小的情况,设f[i][j]表示长度为i,在ac自动机上j点的方案数,直接dp即可。
对于加入串len<=2的情况,对于每个j拆成两个点矩阵快速幂即可。
code
using namespace std;
int const mn=100+9,mm=4*1e5+9,mo=1e9+7,inf=1e9;
int n,m,l,pon,tag[mn],fail[mn],q[mn],map[mn][30],f[mn][mn],ans[209][209],
mat[209][209],tmp[209][209];
char s1[mn][mn],s[mn];
void multansmat(){
fo(i,0,2*pon+1)fo(j,0,2*pon+1)tmp[i][j]=0;
fo(i,0,2*pon+1)fo(j,0,2*pon+1)if(ans[i][j])fo(k,0,2*pon+1)tmp[i][k]=(tmp[i][k]+1ll*ans[i][j]*mat[j][k])%mo;
fo(i,0,2*pon+1)fo(j,0,2*pon+1)ans[i][j]=tmp[i][j];
}
void multmatmat(){
fo(i,0,2*pon+1)fo(j,0,2*pon+1)tmp[i][j]=0;
fo(i,0,2*pon+1)fo(j,0,2*pon+1)if(mat[i][j])fo(k,0,2*pon+1)tmp[i][k]=(tmp[i][k]+1ll*mat[i][j]*mat[j][k])%mo;
fo(i,0,2*pon+1)fo(j,0,2*pon+1)mat[i][j]=tmp[i][j];
}
int main(){
//freopen("sorcery.in","r",stdin);
//freopen("sorcery.out","w",stdout);
freopen("d.in","r",stdin);
freopen("d.out","w",stdout);
scanf("%d%d%d\n",&n,&m,&l);
fo(i,1,n)scanf("%s\n",s1[i]+1);
fo(cas,1,m){
scanf("%s\n",s+1);
int now=0,pre,len=strlen(s+1);
fo(i,1,len)
now=map[now][s[i]-'a']=(map[now][s[i]-'a'])?map[now][s[i]-'a']:++pon;
tag[now]=1;
}
int ti=0;
fo(i,0,25)if(map[0][i])q[++ti]=map[0][i];
fo(i,1,pon){
fo(j,0,25)if(map[q[i]][j]){
int next=map[q[i]][j];
fail[next]=fail[q[i]];
while(fail[next]&&(!map[fail[next]][j]))
tag[next]|=tag[fail[next]],
fail[next]=fail[fail[next]];
fail[next]=map[fail[next]][j];
q[++ti]=next;
tag[next]|=tag[q[i]];
tag[next]|=tag[fail[next]];
}
}
if(l<=100){
f[0][0]=1;
fo(i,0,l)fo(j,0,pon)if(f[i][j])fo(cas,1,n){
int now=j,ok=!tag[j],len=strlen(s1[cas]+1);
fo(k,1,len){
while(now&&(!map[now][s1[cas][k]-'a']))now=fail[now];
now=map[now][s1[cas][k]-'a'];
if(tag[now]){ok=0;break;}
}
if(ok)f[i+len][now]=(f[i+len][now]+f[i][j])%mo;
}
int ans=0;
fo(j,0,pon)ans=(ans+f[l][j])%mo;
printf("%d",ans);
}else{
ans[1][pon+1]=1;
fo(cas,1,n){
int now,ok,len=strlen(s1[cas]+1);
fo(i,0,pon)if(!tag[i]){
now=i;ok=1;
fo(j,1,len){
while(now&&(!map[now][s1[cas][j]-'a']))now=fail[now];
now=map[now][s1[cas][j]-'a'];
if(tag[now]){ok=0;break;}
}
if(len==1)mat[i+pon+1][now+pon+1]+=ok;
else mat[i][now+pon+1]+=ok;
}
}
fo(i,0,pon)mat[i+pon+1][i]++;
while(l){
if(l&1)multansmat();
multmatmat();
l>>=1;
}
int anss=0;
fo(j,0,pon)anss=(anss+ans[1][j+pon+1])%mo;
printf("%d",anss);
}
return 0;
}