初学ac自动机。还要努力。参考了许多代码,仿佛是拷贝的一样了。。。。
// hdu Aho-Corasick automation.cpp : 定义控制台应用程序的入口点。 // #include <iostream> #include <algorithm> #include <queue> #include <string> #include <cstring> #include <cstdlib> #include <cstdio> using namespace std; int n; char str[1100000]; int ans; struct node { int f; node *fail,*next[26]; node() { f=false; fail=NULL; memset(next,NULL,sizeof(next)); } }*root; void ini() { char s[55]; cin>>n; ans=0; root=new node; root->fail=NULL; root->f=false; memset(root->next,NULL,sizeof(root->next)); for(int i=1;i<=n;i++) { scanf("%s",s); node *tmp=root; for(int j=0;s[j]!='