hnu 2243 考研路茫茫――单词情结 AC自动机+矩阵冥累加和(二)

2014-11-24 09:41:17 · 作者: · 浏览: 1
}
qt.push(front->next[i]);
}
else
{
front->next[i] = front == pRoot pRoot : front->fail->next[i];
}

//这里必须要加上front->flag为false的判断么 加不加会生成不同的矩阵
if (!front->next[i]->flag)
{
++M.nD[front->no][front->next[i]->no];
}
}
}
}

int main()
{
int nN;
INT nL;
Matrix M(0);

while (scanf("%d%I64u", &nN, &nL) == 2)
{
InitTrie(pRoot);
while (nN--)
{
scanf("%s", szPat);
Insert(pRoot, szPat);
}
BuildAC(pRoot, M);

Matrix tmp(1);
tmp.nD[0][0] = 26;
tmp = SumPowMatrix(tmp, nL);
INT nAns = tmp.nD[0][0];
Matrix msum = SumPowMatrix(M, nL);
for (int i = 0; i < msum.nSize; ++i)
{
nAns -= msum.nD[0][i];
}
printf("%I64u\n", nAns);
}

return 0;
}