链接:http://acm.hdu.edu.cn/showproblem.php?pid=5384
思路:没学自动机时以为是道KMP然后就tle了好几把,AC自动机模板题
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<vector> 7 #include<queue> 8 #include<iterator> 9 #include<vector> 10 #include<set> 11 #define dinf 0x3f3f3f3f 12 #define LL long long 13 using namespace std; 14 const int N=100010; 15 16 int n, m; 17 string str[N]; 18 char s[N]; 19 20 struct node 21 { 22 int num; //以本节点结尾的单词个数 23 node *child[26]; //孩子 24 } pos[N*50]; 25 node *tree_gen; 26 27 int node_cnt; 28 node * create_node() 29 { 30 pos[node_cnt].num=0; 31 for(int i=0; i<26; i++) 32 pos[node_cnt].child[i]=0; 33 return &pos[node_cnt++]; 34 } 35 36 void insert_tree(char *p) 37 { 38 node *node_p=tree_gen; //指向树根 39 while(*p!='