Codeforces 432D Prefixes and Suffixes (KMP、后缀数组)

基于Kubernetes的ML平台架构设计 本文在Kubernetes开源组件的基础上,对ML平台各部分组件的作用进行了介绍,并且进行了组件选型,初步设计了ML平台的技术架构。 阅读详情

题目链接: https://codeforces.com/contest/432/problem/D

题解:

做法一: KMP

显然next树上\(n\)的所有祖先都是答案,出现次数为next树子树大小。

做法二: 后缀数组/Z-box

按照height分组,二分查找即可。

这种题经常KMP和Z-box都能做。

另外哪位神犇教我一下扩展KMP和Z-box有啥区别。

代码

KMP:

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<utility>
using namespace std;

const int N = 1e5;
char a[N+3];
int nxt[N+3];
int sz[N+3];
vector<pair<int,int> > ans;
int n;

void KMP()
{
    nxt[0] = nxt[1] = 0;
    for(int i=2; i<=n; i++)
    {
        nxt[i] = nxt[i-1];
        while(nxt[i] && a[nxt[i]+1]!=a[i])
        {
            nxt[i] = nxt[nxt[i]];
        }
        if(a[nxt[i]+1]==a[i]) nxt[i]++;
    }
}

int main()
{
    scanf("%s",a+1); n = strlen(a+1);
    for(int i=1; i<n+1-i; i++) swap(a[i],a[n+1-i]);
    KMP();
    for(int i=1; i<=n; i++) sz[i] = 1;
    for(int i=n; i>=1; i--) sz[nxt[i]] += sz[i];
    for(int i=n; i>0; i=nxt[i])
    {
        ans.push_back(make_pair(i,sz[i]));
    }
    printf("%d\n",ans.size());
    for(int i=ans.size()-1; i>=0; i--) printf("%d %d\n",ans[i].first,ans[i].second);
    return 0;
}
重磅!AI实时读取总结微信聊天记录,附MCP协议+智能体配置教程! 【摘要】本文介绍了一套AI实时分析微信聊天记录的解决方案,通过Chatlog+Trae+MCP协议实现智能整理群聊信息。Chatlog作为开源工具本地解析微信数据,确保隐私安全;Trae提供AI分析能力,支持自然语言处理。操作步骤包括:1)下载运行Chatlog并启动HTTP服务;2)安装Trae配置MCP协议;3)创建智能体设置提示词。该方案虽需初始配置,但能有效解决群聊信息过载问题,自动提炼关键内容,避免有价值信息被淹没。文中提供了详细教程链接和网盘资源。 阅读详情

相关推荐

QT播放器插件内嵌浏览器配合流媒体实现国标摄像头网页端播放

基本原理在浏览器⽹页中的指定播放窗口的位置和⼤⼩,实现⼀个内嵌到⽹页中显⽰的播放窗⼝,前端还必须可对这个内嵌播放窗⼝进⾏控制,⽽且播放窗⼝必须跟随浏览器窗⼝的移动和缩放、⽹页滚动、标签页切换、关闭等操作进⾏⾃动联动。播放器可以通过QT实现。这个播放窗⼝同时提供Web Socket的服务端和JSON打包命令的解析执⾏模块,前端就可以通过Web Socket连接后发送JSON打包的控制命令实现控制播放窗⼝。

cameravision的博客 568

CodeForces - 432D Prefixes and Suffixes ( kmp + dp )

题目链接:点击进入 题目 题意 对所有,长度为 i 的,且存在一个长度为 i 的后缀与它相等的,这样一个前缀,输出长度以及出现次数。 思路 next 数组的应用,对于每个位置 i ,通过 next [ i ] ,可以知道长度为 next [ i ] 前缀在中间出现一次,因此可以倒序 dp 计算每个前缀出现的次数,然后通过 l = next [ l ] ( l 初始值 len ),遍历所有存在相等后缀的前缀 。 dp [ next [ i ] ] += dp [ i ] ( dp 初始值 1 , 因为前缀

Cosmic_Tree的博客 433

【mip-NeRF】使用一组二维图像渲染3D场景视频(mip-NeRF论文复现)

本文对mip-NeRF模型的pytorch实现进行了复现

Ryan2k的博客 1860

CodeForces 432D (字符串,next数组)

题意: 给出一个字符串str,问前缀与后缀匹配的串在str中出现了几次。 思路: 前缀与后缀匹配就是next数组的意义,根据next数组可以从后往前统计出子串在母串中出现的次数。 代码: #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;algorithm&gt; #include &lt;cstring&g...

陋室 498

three.js中如何高效加载并播放GLB格式的3D动画

本文详细介绍了在three.js中高效加载并播放GLB格式3D动画的最佳实践。通过对比GLB与GLTF格式的优势,提供从环境搭建、模型加载到动画控制的完整解决方案,并分享性能优化技巧和常见问题排查方法,帮助开发者提升3D动画项目的开发效率和用户体验。

weixin_27890975的博客 364

SDR实战(五)-AD9361多芯片同步技术详解

本文详细解析了AD9361多芯片同步技术在SDR系统中的实现方法,涵盖硬件连接方案、软件配置流程及同步验证技巧。通过等长时钟走线、低抖动时钟分配和精确的SYNC信号控制,解决MIMO系统中多AD9361芯片的时钟同步难题,提升系统性能与稳定性。

weixin_30952535的博客 768

Codeforces 432D Prefixes and Suffixes kmp扩展操作,后缀数据结构

文章目录题意题解 problem redive 题意 求字符串中每一个相等前后缀的长度以及其在全字符串中出现的次数. 题解 本题非常精妙. 首先思考求长度.可以使用kmp和哈希算法,但是哈希不能求出出现次数,因此被消灭了. 那考虑kmp解决第一个问题. kmp中的next数组表示的是全字符串的第i个前缀中前后缀的最大匹配长度. 对于全串来说,长度为lenlenlen肯定是符合要求的,而next[len]next[len]next[len]必然也符合要求,同理next[next[len]]next[next[

Fuko_Ibuki的博客 1万+

大模型-internvl高通qnn运行源码解读

模型链接:https://huggingface.co/OpenGVLab/InternVL2-2B论文官方简要说明 https://internvl.github.io/blog/2024-07-02-InternVL-2.0中文解读 https://zhuanlan.zhihu.com/p/702946079在线demo https://internvl.opengvlab.com/

点滴的岁月 1840

CodeForces - 432D Prefixes and Suffixes (KMP)

题目vj链接 题面: 题意: 给定一个字符串 SSS,计算 SSS 中前缀和后缀相等的串在 SSS 中出现了多少次。 按照长度递增的顺序输出 SSS 中前缀和后缀相等的串在 SSS 中出现的次数。 题解: 先统计对于每一个前缀 S[1,i]S[1,i]S[1,i] 在 SSS 中出现了多少次,然后通过跳 nt[i]nt[i]nt[i],找到前缀与后缀相等的串。 代码: #include<iostream> #include<cstdio> #include<cstdlib&

_Griefs 382

【DeepSeek+Office/WPS】智能办公新时代的全新利器

DeepSeek是一家专注于通用人工智能技术研发的中国科技公司,其核心产品DeepSeek-R1是一款开源的推理大模型,专注于复杂任务的高效处理,支持智能对话、文本生成、语义理解、计算推理、代码生成与补全等多种应用场景。作为国产、免费、开源且强大的AI平台,DeepSeek不仅致力于为终端用户提供高质量的智能服务,还为开发者提供了一整套完善的技术解决方案,帮助他们快速构建和部署自己的智能应用。

2303_77200324的博客 2795

45、数据挖掘学术文献推荐

本文是一篇关于数据挖掘领域的重要学术文献推荐,涵盖了经典理论与最新研究成果。内容包括关键研究论文、综述文章、教科书和专著的介绍,以及来自顶级会议和期刊的出版物推荐。此外,还探讨了数据挖掘与其他领域的交叉研究,如机器学习、统计学和数据库系统,并列举了多个实际应用案例。最后,分析了数据挖掘的未来发展趋势,如更加智能化的算法、高效的计算平台及隐私保护技术。无论是初学者还是专业人士,这些文献都将提供宝贵的学习资源和前沿动态。

qsc90123456的博客 230

CodeForces 432D

这题也想了很久,智商捉急。求相同前缀和后缀在串中出现了多少次,用num数组表示出现了多少次,由于next数组树的性质,而且一定保证越后面的深度约大,所以先把num数组全赋值为1,然后再从后往前扫,num[nxt[i]]+=num[i]#include #include #define maxl 1000020 int n,tlen,cnt; int nxt[maxl],num[ma

binarycopycode 470

Vue3 + uniapp 踩坑:iOS 真机调试一直报错Maximum call stack size exceeded,和(in promise)MiniProgramError err的解决方法

不是你写错代码,是微信开发工具和 iOS 真机调试的兼容问题。开个空项目都报错,勾个设置就没问题,不是你,是工具的锅。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1273

Codeforces 432D Prefixes and Suffixes

题目链接:http://codeforces.com/problemset/problem/432/D 我觉得挺难。 emmm…没有觉得不难的。最近在练习kmp,这个题的第一问求前后缀的长度利用next数组我还是会的,关键是求出现的次数。 怎么说…我真的不会。然后看大量题解,也是千篇一律。大部分都是dp。由于我也不会dp而且讲解也模棱两可,我就凭借自己说服了自己,然后感觉接受了。其实知道了那个状态...

朝夕 378

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

CF432D Prefixes and Suffixes kmp+dp

原题:http://codeforces.com/contest/432/problem/D 题解:求所有前后缀相同的子串的个数。kmp中的nxt数组就是前后缀相等的最大长度,只要将j=nxt[nxt[i]]做到刚好大于0就行了。考虑dp有:f[i]表示1-i的字符串出现的个数,f[nxt[i]]+=f[i],所有应该从后往前扫描统计答案。 #include&lt;cstdio&gt; #i...

Exception 322

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

Codeforces 432D Prefixes and Suffixes:KMP + dp

题目链接:http://codeforces.com/problemset/problem/432/D 题意:   给你一个字符串s,让你找出所有既是前缀又是后缀的子串,并输出它们分别出现了多少次。 题解:   先对原串求一次nex数组。   然后枚举位置i:     sub(k)表示前缀s[0 to k]     dp[i]表示sub(i)在原串s中的出现次数  ...

a1392136的博客 274

Codeforces 432D Prefixes and Suffixes (拓展KMP+KMP)

题目链接:https://codeforces.com/problemset/problem/432/D 题目大意:问前缀和后缀相同的字符串位置和在字符串中出现的次数 题目思路:一种是先用拓展KMP,然后位置加上next数组正好是len的就是符合要求的,还有一种是直接用kmp往回跳,也是符合要求的,然后就是可以发现一个性质,就是如果从后往前,所有人都把自己的num给前一个next的...

smilestruggler_Fly To Higher 338

Codeforces432 D. Prefixes and Suffixes(kmp+dp)

题意: 给定一个长度不超过1e5的字符串, 对于每种既是前缀又是后缀的子串,输出该子串出现的次数 解法: kmp可以计算出所有既是前缀又是后缀的子串长度: 一开始令temp=len,不断temp=nt[temp],中间出现的就是满足条件的长度(kmp问题,这里不详讲) 然后就是计算每种nt[i]在 code: ...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 317

CodeForces - 432D Prefixes and Suffixes(KMP的next数组性质)

题目链接:点击查看 题目大意:给出一个字符串,求满足条件的所有子字符串在主串中出现的次数,条件就是当前子字符串在主串中既是前缀也是后缀 题目分析:因为今天小冰给我讲了一个与next数组配合的dp,也就是dp[i]代表的就是截止到i为止的前缀在主串中出现的次数,和这个题简直是般配,直接先对主串跑一遍next,再对next跑一遍dp,然后利用next[n]不断回溯即可,因为回溯时得到的答案都是反着...

Falcon的博客 468

CodeForces 432D Prefixes and Suffixes

Description You have a strings = s1s2...s|s|, where|s|is the length of strings, andsiitsi-th character. Let's introduce several definitions: A substrings[i..j](1 ≤ i ≤ j ≤ |s|)o...

aims714563740的博客 299

Codeforces 432 D. Prefixes and Suffixes(KMP+DP)

You have a string s = s 1 s 2…s |s|, where |s| is the length of string s, and s i its i-th character. Let’s introduce several definitions: A substring s[i…j] (1 ≤ i ≤ j ≤ |s|) of string s is string s i s i + 1…s j. The prefix of string s of length l (1 ≤ l

tomjobs的博客 519

【代码超详解】Codeforces 432D. Prefixes and Suffixes(KMP 的 next 数组的应用,46 ms)

传送门 一、题目描述 D. Prefixes and Suffixes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You have a string s = s1s2…s|s|, where |s| is the lengt...

COFACTOR 364

Prefixes and Suffixes CodeForces - 432D KMP

题意: 给你一个长度为n的长字符串,“完美子串”既是它的前缀也是它的后缀,求“完美子串”的个数且统计这些子串的在长字符串中出现的次数 思路: 找出完美子串个数不用说 next数组的本质 问题在于统计每个完美子串的出现次数 我们从后往前统计,对于每个位置i 对应的子串0~i 记作S1吧,考虑他的next[i]的前缀 即 0 ~next[i],记作S2吧 如果S1出现一次,那么S2肯定会出现 所以我...

青春苦瓜 160

Codeforces 432D Prefixes and Suffixes (kmp+dp)

发现这个水题 一眼就感觉是 \(kmp\), 因为 \(nxt\) 数组天生就是干这种事情的 答案集合就是从 \(n\) 跳 \(nxt\) 所能跳到的所有节点 那个出现次数怎么搞? 显然可以 \(dp\) \(dp[i]\) 表示跳到 \(i\) 的方案数 然后倒叙枚举 \(i\), \(dp[nxt[i]]+=dp[i]\) 然后就没了 #include <map> #i...

weixin_30484247的博客 250

(cordforce432D)Prefixes and Suffixes(KMP+dp)

题目链接:Problem - 432D - Codeforces 题意:就是求给定字符串中每一个公共前后缀出现的次数。 分析:这道题目用的是kmp+dp,我们想一下kmp中ne[i]的含义,不就是1~i的子串中最长公共前后缀的长度吗,也就意味着1~i这个字符串出现一次,一定会伴随着 i-ne[i]+1~i 这个字符串出现一次,又因为1~ne[i]的字符串与i-ne[i]+1~i这个字符串相同,也就是说1~i这个子串就会多出现一次,所以就有了动态转移方程:dp[i]+=dp[ne[i]],其他就没什么..

AC__dream的博客 326

#432D. Prefixes and Suffixes (exKMP裸题) Codeforces Round #246 (Div. 2)

题目链接: http://codeforces.com/problemset/problem/432/D 题目大意: 有多少个后缀与前缀匹配,并且输出总共能匹配多少个。 题目思路: (鑫爹:这特么不拓展KMP裸题吗,你干啥呢?) 跑一边拓展KMP我们就可以得到要输出的第一个数字了,第二个数字就是查询Next数组里有多少个比这...

qq_41645482的博客 246

CodeForces 432D|Prefixes and Suffixes|KMP|动态规划

题目大意求s的不同长度的既是s前缀又是s后缀的子串的个数题解考虑KMP的next数组。 因为next[j]表示lcp(s[1..j],s[1..k])(k<j)lcp(s[1..j],s[1..k])(k<j)。 故s[1..j]与s[1..next[j]]的关系是后者是前者的最长后缀,由于是最长,所以肯定不会漏情况,因此后者的出现次数是前者的出现次数+1(前者最后一次出现的后缀)。。。。。。。

とある黄鱼のOIブログ 754
上一篇: BZOJ 4567 [SCOI2016]背单词 (Trie树、贪心)
下一篇: BZOJ 1444 [JSOI2009]有趣的游戏 (AC自动机、概率与期望DP、矩阵乘法)
suncongbo
博客等级 码龄9年 32粉丝 302原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值