Luogu P3796 (ac自动机,求模式串在文本串中出现的次数)

本文介绍了一道使用AC自动机解决的裸题,主要任务是计算模式串在文本串中的出现次数,并找出出现次数最多的模式串。同时,通过简单修改,可以判断模式串是否存在于文本串中。
摘要由CSDN通过智能技术生成

AC自动机的裸题,

求模式串在文本串中出现的次数。并输出出现次数最多的字符串。

还有的就是求模式串有没有在文本串中出现过。

只要改一下 询问中for循环就行。

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define mem(x,v) memset(x,v,sizeof(x)) 
#define go(i,a,b)  for (int i = a; i <= b; i++)
#define og(i,a,b)  for (int i = a; i >= b; i--)
using namespace std;
typedef long long LL;
const double EPS = 1e-10;
const int INF = 0x3f3f3f3f;
const int N = 2e4+10;
struct Tree{
	int fail;
	int vis[27];
	int num;
	string t;
}Ac[N];
struct node{
	string s;
	int id;
	bool operator <(const node &a)const{
		return id < a.id;
	}
}p[200];
int ans,cnt,cur[N],tt,tot;
bool vis[N];

void Clean(int x){
	mem(Ac[x].vis,0);
	Ac[x].fail = 0;
	Ac[x].num = 0;
	cur[x] = 0;
}

void Build(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值