著名的国外设计网站有哪些,重庆建网站优化,百度推广按点击收费,上海影视传媒公司排名正题
luogu 5357 题目大意
给你若干单词和一个字符串#xff0c;让你查询每个单词在字符串中出现的次数 解题思路
AC自动机模板
先把单词丢进去#xff0c;然后拿字符串去跑#xff0c;每到一个点累计答案
因为数据较大#xff0c;所以要先存起来#xff0c;跑完后按…正题
luogu 5357 题目大意
给你若干单词和一个字符串让你查询每个单词在字符串中出现的次数 解题思路
AC自动机模板
先把单词丢进去然后拿字符串去跑每到一个点累计答案
因为数据较大所以要先存起来跑完后按照bfs的倒叙传递答案 代码
#includecstdio
#includecstring
#includeiostream
#includealgorithm
#define ll long long
#define N 200021
using namespace std;
int n, w, hd, tl, d[N], v[N], a[N], b[N], nx[N], to[N][30];
char s[N], ss[N*10];
int insert(char* s)
{int n strlen(s1), now 0;for (int i 1; i n; i){int y s[i] - a;if (!to[now][y]) to[now][y] w;now to[now][y];}return now;
}
void bfs()
{hd tl 0;for (int i 0; i 26; i)if (to[0][i]) d[tl] to[0][i];while(hd tl){int h d[hd];for (int i 0; i 26; i)if (!to[h][i]) to[h][i] to[nx[h]][i];else nx[to[h][i]] to[nx[h]][i], d[tl] to[h][i];}return;
}
void ask(char* s)
{int n strlen(s1), now 0;for (int i 1; i n; i){int y s[i]- a;now to[now][y];b[now];//记录答案}return;
}
int main()
{scanf(%d, n);for (int i 1; i n; i){scanf(%s, s1);v[i] insert(s);}bfs();scanf(%s, ss1);ask(ss);for (int i tl; i 0; --i)//传递答案{int x d[i];a[x] b[x];b[nx[x]] b[x];}for (int i 1; i n; i)printf(%d\n, a[v[i]]);return 0;
}