hdu2222 AC自动机模板

AC自动机模板+例题(HDU2896+HDU3065+HDU2222) 病毒侵袭中(HDU2896) #include<map> #include<cmath> #include<queue> #include<vector> #include<cstdio> #include<string> #include<cstdlib> #include<cstring> ... 阅读详情

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2222

题解:AC自动机的本质是将模式串建成字典树跑kmp。首先新建字典树,bfs预处理失败指针,查找就可以。

#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int N=5e5+5;
int trie[N][26];
int mark[N],nxt[N],tot,cas,n;
char s[1000010];
queue<int> q;
inline void ins(char *s){//建字典树	
	int len=strlen(s+1);
	int p=1;
	for(int i=1,c;i<=len;i++){
		c=s[i]-'a';
		if(!trie[p][c]) {
			trie[p][c]=++tot;memset(trie[tot],0,sizeof trie[tot]); 
		}
		p=trie[p][c];
	}
	mark[p]++;
}
void bfs(){
	//fail指针 
	for(int i=0;i<26;i++) trie[0][i]=1;
	q.push(1);nxt[1]=0; 
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=0;i<26;i++){
			if(!trie[u][i]) trie[u][i]=trie[ nxt[u] ][i];	//小优化 
			else {
				q.push(trie[u][i]);
				int v=nxt[u];
				while(v>0 && !trie[v][i]) v=nxt[v];
				nxt[trie[u][i]]=trie[v][i];
			}	
		}
	} 
}
int query(char *s){
	int len=strlen(s+1);
	int p=1;int ans=0;
	for(int i=1,c,k;i<=len;i++){
		c=s[i]-'a';
		k=trie[p][c];
		while(k>1){
			ans+=mark[k];mark[k]=0; 	
			k=nxt[k];
		} 
		p=trie[p][c];
	}
	return ans;
} 

int main(){
//	freopen("hdu2222.in","r",stdin);
	scanf("%d",&cas);
	while(cas--){
		memset(mark,0,sizeof mark);
		for(int i=0;i<26;i++) trie[0][i]=1,trie[1][i]=0;		
		tot=1;
		scanf("%d",&n); 
		for(int i=1;i<=n;i++){
			scanf("%s",s+1);ins(s);
		} 
		bfs();
		scanf("%s",s+1);
		
		printf("%d\n",query(s));
	}
	return 0;
} 

 

Halcon实战:基于图像清晰度自动筛选最佳对焦图片 本文详细介绍了如何使用Halcon实现基于图像清晰度的自动筛选最佳对焦图片技术。通过分析灰度值统计和标准差等核心指标,结合实战代码示例,帮助开发者高效处理工业检测中的对焦问题,提升自动化检测的准确性和效率。 阅读详情

相关推荐

IMU预积分【SLAM】

预积分的推导过程比较多,所以这里只记录关键结论。 其实这些公式不太好记忆,因为预积分推导过程的想法来源很巧妙,无法看出物理意义。一切推导的来源: 最好记忆的旋转相对运动量: △Rij≐RiTRj=∏k=ij−1Exp((ω~k−bg,k−ηgd,k)△t)\triangle R_{ij} \doteq R_{i}^{T}R_{j} = \prod_{k=i}^{j-1}Exp((\tilde{\omega}_{k}-b_{g,k}-\eta_{gd,k})\triangle t) △Rij​≐RiT​Rj​

Tong_1024_的博客 1382

AC自动机模板(hdu2222)

具体学习参考https://blog.csdn.net/creatorx/article/details/71100840 模板来自kuangbin大神,HDU2222模板题 //====================== // HDU 2222 // 求目标串中出现了几个模式串 //==================== #include&lt...

bahuan1974的博客 134

【本体】Protege高效批量导入实例(Individuals)的自动化实践

本文详细介绍了在Protege中高效批量导入实例(Individuals)的自动化实践方法。通过分析Protege本体文件结构,提供Python脚本示例,帮助用户快速处理大规模数据导入,显著提升知识图谱构建效率。特别适合需要处理数千个实例的医疗、制药等领域应用。

weixin_30275415的博客 410

hdu 2222 AC自动机模板题

首先学KMP   推荐《算法导论》以及本人的KMP博文 http://blog.csdn.net/u011026968/article/details/10382659 在学Trie  这个其实不难,随意找点资料就行 然后开始学AC自动机  http://www.cppblog.com/mythit/archive/2014/03/09/80633.html#206110  这个博文的讲解很好

Pilgrim 1365

Godot4 TileMap分层绘制全攻略:解决角色、树木遮挡混乱,打造正确视觉层级

本文详细介绍了Godot4 TileMap分层绘制技术,通过图层管理和Y-Sort功能解决2D游戏中角色与物体的遮挡问题。从基础图层设置到高级优化策略,帮助开发者打造符合自然视觉规律的场景层次,提升游戏沉浸感。特别针对TileMap和TileSet的使用提供了实用技巧和代码示例。

weixin_28717411的博客 522

Linux运维踩坑实录:手把手教你修复LVM中PV显示[unknown]的诡异问题

本文详细解析了Linux运维中LVM物理卷(PV)显示[unknown]的故障现象及修复方法。通过分析问题根源、提供标准修复流程和特殊场景处理方案,帮助运维人员快速解决VG容量异常、PV状态丢失等问题,并分享预防措施与最佳实践,确保LVM存储系统的稳定运行。

weixin_26869081的博客 360

AC自动机模板 hdu2222

#include #include #include #include #include #include               #include                //AC自动机模板题(动态建立) hdu2222 using namespace std; char a[1000005], b[55]; struct trie { trie *

u012432475的专栏 611

Rust 语言入门

Rust 使 对您的编辑或工具或代码所在的位置没有特定要求,因此 如果您更喜欢使用集成开发环境 (IDE) 而不是 命令行,请随意使用您最喜欢的 IDE。对于简单的程序来说,只编译 是可以的,但作为你的项目 增长,您将需要管理所有选项并轻松共享您的 法典。接下来,我们将向您介绍 Cargo 工具,它将帮助您编写 真实世界的 Rust 程序。现在您已经安装了 Rust,是时候编写您的第一个 Rust 程序了。这不重要 到你的代码所在的 Rust,但对于本书中的练习和项目, 我们建议在你的主目录中创建一个。

JohnChen(Net) 1495

AC自动机初学(模板)+ HDU 2222

        AC自动机这个东西,听起来很高大上,在高中的时候不知道什么是自动机,以为写出了AC自动机就可以自动AC……        现在知道了它是用来解决字符串匹配问题的东西,说白了就是KMP+Trie。这个在去年暑假的时候,hc学长也略微提到过,但是没有具体的讲。        在解决只有一个模式串的匹配问题的时候,我们用朴素的KMP算法即可快速完成,但是,如果有很多个匹配串呢?这是就得用...

alpc_qleonardo 507

(持续更新中!)详解【计算机类&面试真题】军队文职考试 ——第二期(真题+解析)| 网络协议的三个核心要素;交互式系统中的非剥夺策略;中断和陷入的区别;可变分区管理中的硬件机制;数据库系统的优点

本篇博客将讨论军队文职面试(计算机类)的几个关键问题。我们将介绍网络协议的核心要素(帮助你理解网络通信的基本原理)、交互式系统中的非剥夺策略(解释为何这是一个优秀的策略以及其对用户体验、系统稳定性和可预测性的影响)、中断和陷入的区别(从引起原因、处理机制、权限级别和应用等方面进行阐述)、可变分区管理的硬件机制以及数据库系统与文件系统的优点比较。通过阅读本文,您将深入了解这些话题,为面试准备和实际应用提供有价值的知识。

追光者♂:记录、分享、总结、提升,现象级专栏《Python从入门到人工智能》作者,无惧黑暗,坚信曙光 1710

肖特基二极管的反向恢复过程

本博客简述肖特基二极管反向恢复过程。

记得诚 1万+

HDU 2222(AC自动机模板题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目大意:多个模式串。问匹配串中含有多少个模式串。注意模式串有重复,所以要累计重复结果。 解题思路: AC自动机模板题。 一开始使用LRJ的坑爹静态模板,不支持重复的模式串。 在做AC自动机+DP的时候,扒了zcwwzdjn大神的动态优化(失配指向root)写法,以及借鉴了网上的AC...

weixin_33869377的博客 115

【论文复现】——基于改进FPFH特征提取的点云模板匹配方法

基于改进FPFH特征提取的点云模板匹配方法 [J]. 应用激光, 2024, 44 (04): 196-204.

点云侠的博客 618

ac自动机模板 hdu2222

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,...

caowenbo2311694605的博客 563

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu2222 ac自动机模板

字符串匹配有kmp,可

一段旅途 491

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

HDU 2222 AC自动机 模板

AC自动机模板题。 #include #include #include #include using namespace std; const int maxn=1000005; const int maxm=500005; int T,n; char s[maxn]; struct Aho { struct state { int next[26],cnt,f

亂丟程式碼的天空 292

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

hdu 2222(AC自动机模板)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2222思路:模板题#include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;cmath&gt; #include &lt;cctype&gt; #include &lt;iostream&...

llmxby 297

HDU 2222 (AC自动机模板)

Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10744    Accepted Submission(s): 3722 Problem Description In

LiQiyao的博客 415

HDU2222 AC自动机静态模板

本蒟蒻第一次做AC自动机好慌哦; http://acm.hdu.edu.cn/showproblem.php?pid=2222 题目的意思不多说了,就是求目标串中有几个模式串。虽然很简单,但不过我还是做了很久。 关于AC自动机,有静态和动态模板两种,静态好像效率比较高,速度也较快(但为什么这道题动态快一点呢),动态好像内存需求有点大,但不过都是基于字典树,还是比较好写的。我觉得静态的比较好写...

KXL5180的博客 247

hdu 2222AC自动机模板题

点击打开链接 题意:问前面给的所有串在最后一个串出现的次数 思路:这道题是AC自动机入门必做的题,所以没什么好说的,是个模版题,推荐一个大神写的算法详解,不懂得可以看一看,反正我是看他的稍稍懂了点 [html] view plain copy #include stdio.h>   #include string.h>   #incl

The_star_is_at的博客 385

hdu 2222 裸的AC自动机静态模板

hdu 2222 裸的AC自动机静态数组模板

wintowanti 1212

AC自动机模板题-HDU-2222-Keywords Search

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2222 Code:AC自动机模板: #include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;queue&gt; using namespace std; struct node{ i...

随风而行的博客 276

【AC自动机_模板】HDU 2222 Keywords Search

HDU 2222 Keywords Search 题意:问文本串中出现了多少种模式串。 AC CODE【AC奥特曼板子题~】 #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include &l...

L_X_ 212

HDU2222 Keywords Search AC自动机模板

HDU2222 Keywords Search 题面: 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. Eve...

Hagtaril 318

HDU 2222 ac自动机入门模板题

Keywords Search Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 56619    Accepted Submission(s): 18519 Problem Description In the mod

大咸鱼。。。 441

AC自动机 模板 【HDU2222】 Keywords Search

AC自动机(Aho Corasick Automaton) 如果匹配字符串,一个模式串,一个匹配串,KMP就搞定了。 但是如果现在有多个模式串怎么办呢?每个模式串都处理一遍,再与匹配串匹配就太慢了,所以有了AC自动机,来解决这类问题。AC自动机可以看成是Trie树和KMP的结合体,具体的实现方式就是在每个节点处增添一个fail指针,作用与KMP中的失配时用的跳转数组差不多(虽然在匹配的大多数时候

Todobe 502
上一篇: hdu1251 Trie字典树模板
下一篇: bzoj1355 kmp最短循环节
Exception2017
博客等级 码龄9年 9粉丝 157原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值