HDU 2222 AC自动机模板

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

题意:给出n个单词,和一篇文章,即一个字符串,求其中有多少个单词出现。
TRICK: ①、重复的单词要分别计算;②、多组数据记得要清空数组,别把不该清的清了,坑死人,最后还是在某位高大佬的帮助下才发现

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<algorithm>
#include<iomanip>
#include<iostream>
#include<cctype>
#define mem(x) memset(x,0,sizeof(x)) 
using namespace std;
int t,n,l,len,tot,head=0,tail=1,tt;
char s[1000001],s1[1000001];
int f[500001][27],q[500001],fail[500001],danger[500001],vis[500001];
//-------------------
inline void f1() //建树
{
    int t=0;
    for(int i=1;i<=l;i++)
    {  if(!f[t][s[i]-'a']) 
         f[t][s[i]-'a']=++tot;
       t=f[t][s[i]-'a'];
    }
    danger[t]++;//统计一个单词的出现个数
} 
//-------------------
inline void ac()
{
    head=0,tail=1;
    int j;
    q[1]=0;
    while(head^tail)
    {
        head++;
        j=q[head];
        if(j)
          for(int i=0;i<26;i++)
            if(f[j][i])
            fail[f[j][i]]=f[fail[j]][i]; //求fail指针
        for(int i=0;i<26;i++)
          if(!f[j][i]) f[j][i]=f[fail[j]][i];
          //优化,如果当前的点没有对应的儿子,我们就将它的儿子跳到最终会到的地方
          else q[++tail]=f[j][i]; 
    }
}
//-------------------
int main()
{
    //freopen("keyword.in","r",stdin);
    scanf("%d",&tt);
    for(int bz=1;bz<=tt;bz++)
    {
        mem(f);
        mem(q);
        mem(fail);
        mem(danger);
        mem(vis);
        tot=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s+1);
            l=strlen(s+1);
            f1();
        }
        scanf("%s",s1+1);
        len=strlen(s1+1);
        ac();

        int now=0,tem,ans=0;
        for(int i=1;i<=len;i++)
        {
            now=f[now][s1[i]-'a'];
            tem=now;
            while(tem && vis[tem]!=bz)
            {
                vis[tem]=bz;
                ans+=danger[tem];
                tem=fail[tem];
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
微信4.1.5.16升级后,你的自动化脚本失灵了?手把手教你用C#让UI树“复活” 微信4.1.5.16版本更新导致自动化脚本失效?本文深入解析微信UI树隐藏的原因,并提供C#实战解决方案,通过UIAutomation技术恢复UI树结构,帮助开发者重新实现自动化操作。涵盖技术原理、代码实现及优化策略,适合RPA开发者和自动化脚本编写者参考。 阅读详情

相关推荐

告别手动拍照!用Python+JAKA机械臂+D455相机实现全自动手眼标定(附完整代码)

本文详细介绍了如何利用Python脚本实现JAKA机械臂与Intel RealSense D455相机的全自动手眼标定流程,提供从硬件配置到代码实现的完整解决方案。通过自动化标定,显著提升工业自动化中的精度和效率,适用于机器人视觉领域的二次开发需求。

weixin_30555125的博客 534

AC自动机模板(hdu2222)

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

bahuan1974的博客 134

从零构建AI Agent集群:Docker Compose与Nginx部署实战

在AI应用开发领域,微服务架构和容器化部署已成为提升开发效率和系统可维护性的关键技术。Docker Compose作为容器编排工具,能够将多个独立服务(如Node.js、Python应用)及其依赖(数据库、缓存)封装在隔离环境中,并通过统一配置文件定义服务间的网络与依赖关系,实现一键启停。Nginx作为反向代理,则提供了统一的网络入口、请求路由和负载均衡能力,是构建高可用Web应用的基石。这种组合技术方案的价值在于,它能将复杂的AI系统(如工作流引擎、对话Agent、技能库)的部署运维复杂度大幅降低,使得开

weixin_27028523的博客 644

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

Windows电脑如何用MobaXterm连接宇树G1机器人?保姆级SSH配置指南

本文提供了一份详细的保姆级教程,指导Windows用户使用MobaXterm通过SSH连接宇树G1机器人。内容涵盖从物理网络配置、MobaXterm安装与SSH会话创建,到文件传输、X11转发等高级功能,并包含常见问题排查与安全加固建议,帮助开发者快速建立稳定可靠的远程开发连接。

purple的博客 888

LVGL 离线字体转换lv_font_conv本地安装

LVGL FONT CONV 离线版本

liu132641的专栏 3413

AC自动机模板 hdu2222

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

u012432475的专栏 611

STM32F407与AD7766实战:如何用SPI+DMA实现高速ADC数据采集(附完整代码)

本文详细介绍了如何利用STM32F407的SPI接口与DMA控制器,高效稳定地驱动24位高精度ADC芯片AD7766,实现高速连续数据采集。通过对比传统中断方式的瓶颈,阐述了SPI+DMA方案如何大幅降低CPU负载,并提供了从硬件设计、CubeMX配置到核心驱动代码的完整实战指南,帮助工程师解决高速ADC数据采集中的性能难题。

weixin_29281941的博客 201

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

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

alpc_qleonardo 507

SwinIR实战:从环境搭建到模型训练的全流程解析

本文提供了SwinIR超分辨率模型从零开始的全流程实战指南。详细解析了基于PyTorch和Anaconda的环境搭建、数据准备与配置文件修改、训练启动与常见错误排查(如张量尺寸不匹配),以及模型评估方法,帮助读者高效部署并训练SwinIR模型。

weixin_28224217的博客 327

第6章: MMU Notifier在KVM虚拟化中的应用

本文分析了KVM如何利用MMU Notifier机制维护客户机与宿主机地址映射一致性。KVM采用三层地址空间转换架构(GVA→GPA→HPA),通过硬件辅助虚拟化(EPT/NPT)实现高效转换。重点探讨了KVM MMU Notifier回调实现,包括invalidate_range_start/end等核心函数,以及HVA范围处理流程。当宿主机内存变化时,KVM通过注册的notifier回调及时更新映射关系,确保虚拟化环境的内存一致性。文章详细解析了相关数据结构和关键代码实现,揭示了KVM内存管理的核心机制

图形/计算GPU的驱动与虚拟化技术分享园地 2354

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

21天教你学会PCIe专栏(15)--高级功能 - SR-IOV 和 MR-IOV

1.1 定义I/O虚拟化(I/O Virtualization):I/O虚拟化是指在虚拟化环境中,通过硬件和软件技术,将物理I/O资源抽象为虚拟I/O资源,提供给虚拟机(VM)使用。1.2 目标性能:提高虚拟机的I/O性能,减少虚拟化开销。隔离:确保虚拟机之间的I/O资源隔离,防止相互干扰。灵活性:灵活分配和管理I/O资源,提高资源利用率。通过今天的学习,你应该对SR-IOV和MR-IOV的基本概念、工作原理、主要特性和应用场景有了深入的了解,掌握了配置和使用这些高级功能的方法。

xiaoheshang_123的博客 1465

HDU 2222(AC自动机模板题)

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

weixin_33869377的博客 114

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

深度学习工具包 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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

hdu2222 AC自动机模板

原题:http://acm.hdu.edu.cn/showproblem.php?pid=2222 题解:AC自动机的本质是将模式串建成字典树跑kmp。首先新建字典树,bfs预处理失败指针,查找就可以。 #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;queue&gt; #include&lt;algorithm&gt; ...

Exception 241

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

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自动机 模板

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

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

hdu 2222AC自动机模板题

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

The_star_is_at的博客 385

HDU2222 AC自动机静态模板

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

KXL5180的博客 247

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

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

wintowanti 1212

【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

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

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
上一篇: 2017.2.21考试总结
下一篇: 2017.3.11 NOIP2017赛前模拟考试总结
Amessal
博客等级 码龄10年 9粉丝 42原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值