AC自动机模板+例题(HDU2896+HDU3065+HDU2222)

这篇博客详细介绍了AC自动机的模板,并通过HDU2896、HDU3065和HDU2222三个例题进行实战讲解,帮助读者理解和掌握AC自动机在解决字符串匹配问题上的应用。特别提到了在HDU2222题目中可能出现的cin、cout超时问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

病毒侵袭中(HDU2896)

#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define PII pair<int, int> 
#define PSS pair<string, string>
#define VINT vector<int> 
#define fi first
#define se second
#define mkp make_pair
#define Pque priority_queue
#define pb push_back
using namespace std;
typedef long long LL;
const int maxn = 1e5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m, tot;
char ss[maxn + 5];
bool vis[maxn + 5];
int fail[maxn + 5], trie[maxn + 5][130];
int bianhao[maxn + 5];//当前结束位置的病毒编号

void getfail(){
	queue<int> q;
	for(int i = 0; i <= 128; i++){
		if(trie[0][i]){
			fail[trie[0][i]] = 0;
			q.push(trie[0][i]);
		}
	}
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(int i = 0; i <= 128; i++){
			if(trie[now][i]){
				fail[trie[now][i]] = trie[fail[now]][i];
				q.push(trie[now][i]);
			}
			else trie[now][i] = trie[fail[now]][i];
		}
	}
	return;
}

int main(){
	scanf("%d", 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值