刷题HDU 2222 Keywords Search
Posted hongyj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了刷题HDU 2222 Keywords Search相关的知识,希望对你有一定的参考价值。
Problem Description
In the modern time, Search engine came into the life of everybody like Google, Baidu, etc.
Wiskey also wants to bring this feature to his image retrieval system.
Every image have a long description, when users type some keywords to find the image, the system will match the keywords with description of image and show the image which the most keywords be matched.
To simplify the problem, giving you a description of image, and some keywords, you should tell me how many keywords will be match.
Input
First line will contain one integer means how many cases will follow by.
Each case will contain two integers N means the number of keywords and N keywords follow. (N <= 10000)
Each keyword will only contains characters ‘a‘-‘z‘, and the length will be not longer than 50.
The last line is the description, and the length will be not longer than 1000000.
Output
Print how many keywords are contained in the description.
Sample Input
1
5
she
he
say
shr
her
yasherhs
Sample Output
3
Description(CHN)
给 (n) 个模式串和一个文本串,求文本串中出现了多少个模式串
Solution
AC自动机裸题,做法跟【刷题】洛谷 P3808 【模板】AC自动机(简单版)一模一样
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=10000+10,MAXM=1000000+10,MAXS=500000+10;
int T,n,ch[MAXS][30],fail[MAXS],ed[MAXS],cnt,vis[MAXS],last[MAXS],ps[MAXN];
char s[MAXM];
std::queue<int> q;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='