2019牛客多校第六场 C.Palindrome Mouse(回文树)

[leetcode]Valid Palindrome (判断回文数 C语言实现) Valid Palindrome Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example, “A man, a plan, a canal: Panama” is a palindrome. “race a 阅读详情

给一个串,问这个串里所有本质不同的回文子串,有多少对满足一个串是另一个的子串。

这题现场过的人很少啊,题解也给了个蛮复杂我还没看懂的带log的做法,其实了解回文树的话特别好想,我们现场写了一个O(n)的做法(在牛客跑了72ms)。回文树还算是个新东西,还没有被玩坏,我以前刷的回文树套题基本都算是板子题,最近多校有几道回文树就进入了灵活运用的范畴了,出题人开始准备玩坏这个算法了,以后这都是基操。

见本质不同,想回文自动机,然后就开始梳理在回文树上,怎样的两个节点表示的回文串有子串关系?

首先是next边,很显然,一条next链上,除奇根偶根,所有父亲都是儿子的子串。
其次是fail边,又又又很显然,一条fail链上,父亲是儿子的后缀,所以除奇根偶根所有父亲都是儿子的子串。

好了这题就快做完了。
对于每个节点,答案就是其next链上除根外的父亲个数+fail链上除根外的父亲个数。
然而仅仅这样还是存在问题,因为next链和fail链有时候存在交叉,也就是说一个回文串既是另一个串的后缀,又在那个串中间出现,比如样例的aaaa,next链上的aa与fail链的aa是同一个节点。

于是还要想办法去个重。在dfs并且对每个节点跳fail树统计的时候,打个vis标记(当前节点也要标记,next链和fail链重的时候就可能会跳到这里),如果下次跳的时候发现了vis,就可以停止了,这样就简单的保证了不交叉,并且防止了fail树重复跳带来的复杂度。

最后,对于跑出来的东西做一个很简单的dp:当前节点贡献 = 父亲贡献 + fail链贡献 + 1。

ac代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int _, kase = 1;
char s[maxn];
ll ans = 0;

struct Pam {
    int next[maxn][26];
    int fail[maxn];
    int len[maxn];// 当前节点表示回文串的长度
    int S[maxn];
    int dp[maxn];
    bool vis[maxn];
    int last, n, p;


    int newNode(int l) {
        memset(next[p], 0, sizeof(next[p]));
        len[p] = l;
        dp[p] = 0;
        return p++;
    }

    void init() {
        ans = 0;
        n = last = p = 0;
        newNode(0);
        newNode(-1);
        S[n] = -1;
        fail[0] = 1;
    }

    int getFail(int x) {
        while (S[n - len[x] - 1] != S[n]) {
            x = fail[x];
        }
        return x;
    }

    void add(int c) {
        S[++n] = c;
        int cur = getFail(last);
        if (!next[cur][c]) {
            int now = newNode(len[cur] + 2);
            fail[now] = next[getFail(fail[cur])][c];
            next[cur][c] = now;
        }
        last = next[cur][c];
    }

    int jump(int x) {
        int cnt = 0;
        vis[x] = 1;
        while (fail[x] != 0 && fail[x] != 1 && !vis[fail[x]]) {
            x = fail[x];
            vis[x] = 1, ++cnt;
        }
        return cnt;
    }

    void clearJump(int x, int cnt) {
        vis[x] = 0;
        while (cnt--) {
            x = fail[x];
            vis[x] = 0;
        }
    }

    void dfs(int x, int fa) {
        int jp = jump(x);
        dp[x] = jp;
        if (x != 1 && x != 0 && fa != 0 && fa != 1) {
            dp[x] = dp[fa] + jp + 1;
        }
        ans += dp[x];
        for (int i = 0; i < 26; ++i) {
            if (next[x][i]) {
                dfs(next[x][i], x);
            }
        }
        clearJump(x, jp);
    }

    void build() {
        init();
        for (int i = 1; s[i]; i++) {
            add(s[i] - 'a');
        }
    }

} pam;


int main() {
    scanf("%d", &_);
    while (_--) {
        scanf("%s", s + 1);
        pam.build();
        printf("Case #%d: ", kase++);
        pam.dfs(1, 1);
//        printf("%lld\n", ans);
        pam.dfs(0, 0);
        printf("%lld\n", ans);
    }
    return 0;
}
GD32 TIMER0 PWM输出死活没波形?别忘了这个关键配置(附完整代码) 本文详细解析了GD32 TIMER0 PWM输出无波形的常见问题,特别强调了高级定时器特有的主输出使能配置。通过完整的代码示例和调试技巧,帮助开发者快速解决PWM输出问题,适用于无刷电机控制等嵌入式应用场景。 阅读详情

相关推荐

用MCP扩展Cursor的5种神奇用法:从文件操作到网页抓取实战

本文深入探讨了如何利用MCP(Model Context Protocol)扩展Cursor AI编程助手,解锁五种高效实用场景。从文件系统操作、网页内容抓取,到数据库查询、Figma设计稿对接,乃至构建自定义MCP服务器,文章通过实战案例展示了如何将Cursor从代码编辑器升级为能理解并操作工作环境的智能助手,显著提升开发效率与自动化水平。

weixin_29231027的博客 317

2019牛客暑期多校训练营(第六场)C-Palindrome Mouse(回文树)

题目链接 题意:给你一个字符串,将其中所有本质不同的回文子串求出来放在一个集合。问集合中一个串是另一个串的子串的对数是多少? 题解:网上看了挺多题解的,但觉得有些没写清楚,所以写了一篇自己的理解… 首先用回文树将所有本质不同的回文串求出来。然后加上fail数组的边,回文树就变成一颗树,且每一个节点都有一条回边的‘图’。问题就变成了找图中有多少对可达点?如果放在一般图中这个问题是不好求的,但由于...

weixin_41665270的博客 254

MSP430开发入门:手把手教你用IAR EW430从建工程到烧录调试(附F5529配置)

本文详细介绍了如何使用IAR Embedded Workbench(EW430)进行MSP430F5529开发板的嵌入式开发,从环境搭建、工程配置到硬件调试全流程。通过实战示例和关键配置技巧,帮助开发者快速掌握MSP430开发的核心要点,包括LED控制、定时器使用和低功耗优化等实用技术。

weixin_30240349的博客 396

2019牛客多校第六场 Palindrome Mouse

题意:求每个本质不同的回文串的所有回文子串的总数 思路:我们统计一个串的回文子串的个数,可以将这些子串分为两类,一类是父亲节点的所有子串(包含父亲节点),另一种是所有可能的回文后缀。注意着两者有交集,所以需要标记是否访问过。这两种包含所有的情况,原因是一个字符串的所有回文子串可以分为两类,一类是包含最后一个字符的,另一类是不包含最后一个字符的。 #include <bits/stdc+...

ehdhg13455的博客 299

计算机三级考试嵌入式系统重点精简汇总

第一章 嵌入式系统概论 1.1.1嵌入式系统 (1)特点:(1)专用性;(2)隐蔽性;(3)资源受限;(4)高可靠性;(5)实时性;(6)软件固化。 (2)应用:(1)冰箱、洗衣机、电饭煲、空调、摄影机、DVD播放器等;(2)数控机床、飞机、汽车、电梯、X光机、血压计等;(3)电话机、传真机、打印机、pos机、GPS导航仪、路由器等。 1.1.2嵌入式系统组成与分类 (1)逻辑组成:硬件和软件,分为处理器、存储器、I|0设备与I|O接口,数据总线; (2)处理器:分为主处理器(CPU)和协处

chemkrik的博客 1万+

python DEA: 基于非径向距离NDDF的Malmquist-Luenberger 指数及其分解

点赞发Nature 关注中Science Malmquist-Lenberger指数(ML指数)是距离函数与DEA计算中常用的指数,ML指数可以进一步分解为技术进步technological progress和效率改善effeciency change. 技术进步常被当做增长模型中的全要素生产率,用到许多计量经济研究中,探讨影响技术进步的环境变量。这里我分享一个考虑非期望产出下的NDDF方法计算ML指数。 该ML指数为global ML(区别于sequential ML) import numpy as

Cmmmmm丶的博客 5301

Palindrome Mouse 回文自动机

link 考虑每个点对答案贡献为除他本身外,所在fail链上节点个数和回文树上该节点祖先节点个数。 这样写会有两个问题 1.重复节点 2.时间复杂度 考虑递推,该节点的贡献为其父亲节点贡献+它所延伸出fail链的个数+1 #include<bits/stdc++.h> using namespace std; typedef long long ll;; const int SZ = 26;///字符集 const int maxn = 1e5 + 6; struct PAM { s

qq_43914084的博客 188

Calibre 3Dstack Flow Example(5-2)

本文详细介绍了Calibre3DSTACK工具在3D-IC设计验证中的应用。主要内容包括:1)连通性检查(LVS)规则编写,重点说明connected命令的使用方法和多文本标签处理;2)设计规则检查(DRC)实现,涵盖层间距检查和焊盘重叠检查;3)系统网表生成器操作流程,从芯片导入到网连通性定义;4)两种规则文件语法(扩展语法和传统语法)的编写示例;5)验证报告文件格式解析。通过具体案例演示了如何建立完整的3D-IC验证流程,包括芯片定义、装配操作、电气连接验证和物理规则检查等关键步骤,为3D-IC设计验证

u013620135的博客 2340

2019牛客暑期多校训练营(第六场)C - Palindrome Mouse (回文树dfs)

题目链接 题意 一个字符串,求有多少对(S,T)(S,T)(S,T),满足S、TS、TS、T是回文串,S是T的子串S是T的子串S是T的子串 思路 题解还没看懂… 看大佬代码,好多在回文树上dfsdfsdfs sz[i]sz[ i ]sz[i]表示nex往下能走多少,节点iii左右能加多少字符串 c[i]c[ i ]c[i]表示fail向上能走多少,节点iii有多少后缀相同的回文串 sz[i]×c[...

Running Bit. 615

路径跟踪 | 图解路径跟踪PID算法(附ROS C++/Python/Matlab仿真)

PID控制是一种经典的控制算法,广泛应用于各种工业场景。在基于PID的局部路径规划中,希望机器人能快速跟踪上预设的轨迹。本文介绍PID控制的基本原理,并基于PID控制律设计路径跟踪算法,最后通过ROS C++/Python/Matlab进行仿真实现,加深理解

FRIGIDWINTER的博客 1万+

jdbc从入门到精通(全)

前言 Java语言连接数据库(Java DataBase Connectivity) 面向接口/抽象编程(降低程序的耦合度,提高程序的扩展力)类似多态机制

码农研究僧的博客 1762

2019牛客多校赛 第六场 C Palindrome Mouse (回文树/回文自动机)

大致题意:给你一个字符串,问这个字符串的子串中,有多少个本质不同的回文串恰好是另外一个回文串的子串,求这样的回文串的对数。 可以说,这是一个回文树/回文自动机的裸题吧。显然,在回文树里面,一个节点的所有后代都是回文串而且包含当前回文串,所以可以直接统计所有节点的size。然后,当前节点的所有后代也包含当前节点的fail回文串,所以后代的贡献也要算到fail上。那么,一个很显然的问题...

alpc_qleonardo 784

【异常】Claude Code 400错误(Extra inputs are not permitted)解决方案

摘要:Claude Code 2.0.37+版本因API请求包含未支持的custom.input_examples参数导致400错误,使核心功能失效。解决方案是降级至稳定版v2.0.32:先卸载当前版本(npm uninstall -g @anthropic-ai/claude-code),再安装指定版本(npm install -g @anthropic-ai/claude-code@2.0.32),最后验证请求是否恢复正常。该问题确认在v2.0.32版本不存在。(148字)

奶爸的编程之路,也就一周冷个三天 2059

2019牛客多校赛 第六场 C Palindrome Mouse (回文树)

题意:给你一个字符串,然后把所以本质不同的回文串放入集合,然后问你有多少pair(a,b),满足a,b是回文串,且a是b的子串,问这样的pair有多少对。 在一个回文树里面,1.每一个节点对应的回文串都next是树里其后代的子串,所以一个节点i和其后代组成的pair的个数现在是sz[i]-1。2.其次每一个节点i对应的回文串又都是fail指针指向他的节点j(fail[j]=i)的子串,也包括j的...

SEIZE THE DAY 227

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

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

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

2019牛客多校第六场 C Palindrome Mouse (回文树)

题目链接:https://ac.nowcoder.com/acm/contest/886/C 解题思路: 想到类似dp的思路,用cnt[fa]记录父节点不包括自身的回文子串总数,那么 当前的总数可以分为3部分 cnt[now] = cnt[fa] + 1(父节点本身) + 当前在父节点串两边新添加的的字母后现在的串能够产生的新的回文串 前两部分没有什么问题,注意cnt[0] 和 cn...

shadiao.的博客 184

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

2019牛客暑期多校训练营(第六场)C Palindrome Mouse (回文树+DFS)

题目传送门 题意 给一个字符串s,然后将s中所有本质不同回文子串放到一个集合S里面,问S中的两个元素\(a,b\)满足\(a\)是\(b\)的子串的个数。 分析 首先要会回文树(回文自动机,一种有限状态自动机) 然后可以很轻松的求出来S集合,我们拿出一个样例画出回文树看一下 abacaba 注: 上图中结点序号只是为了方便描述,与实际建树并不一定相同 0和1分别为偶数根和奇数根,黄边...

weixin_30711917的博客 131

2019牛客暑期多校赛第六场 C Palindrome Mouse 回文树上dfs

链接:https://ac.nowcoder.com/acm/contest/886/C 来源:牛客网 题目描述 Doctor has a string s consisting of only lowercase letters. Doctor has got the set of all palindromic substrings of a string s, denoted by th...

lt的博客 245

Palindrome Mouse - 回文树 & dfs

这道题是牛客2019暑期多校第六场的C题,题目链接 大意是,给出一个字符串,对于它所有的回文子串,若其中某个是另一个的子串,则视其为一对,求总对数。 看到回文子串就想到了回文树。简单回顾一下,回文树每个节点代表以当前字符结尾的最长回文子串,next指向前后添上某个字符后更大的那个子串,fail(suffix)指向当前子串的最长回文后缀。初步的想法是,对于某个节点,它fail链上的所有节点以及反...

rgndao的博客 222

题解 | Palindrome Mouse-2019牛客暑期多校训练营第六场C题

题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss 题目描述: 输入描述: 输出描述: 示例1: 题解: 代码: #include <bits/stdc++.h> const int max_N = (int)1e5 + 21; const int sigma = 26; int n; char s[max_N]...

lastbye的博客 247

Palindrome Mouse(2019年牛客多校第六场C题+回文树+树状数组)

目录 题目链接 题意 思路 代码 题目链接 传送门 题意 问\(s\)串中所有本质不同的回文子串中有多少对回文子串满足\(a\)是\(b\)的子串。 思路 参考代码:传送门 本质不同的回文子串肯定是要用回文树的啦~ 在建好回文树后分别对根结点为\(0,1\)...

di6499的博客 211

[2019牛客多校训练第6场]Palindrome Mouse

链接:https://ac.nowcoder.com/acm/contest/886/C 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 分数:2800 题目描述 Doctor has a string sss consisting of only lowercase letters. Doctor has got the se...

dxyinme-Zz 214

2019牛客暑期多校训练营(第六场)C Palindrome Mouse —— 回文自动机求一个回文串是另一个回文串子串的个数

This way 题意: 给你一个字符串,问你本质不同的回文串中有多少对是含有子串关系的 题解: 我们可以从子串找母串,每次枚举长度为奇数或者偶数的字符串,向外边扩,同时加上fail指针的个数,假设baaabaaab,它肯定是从aaabaaa转移过来的,那么它就已经包括了aaa的内容。 对于本地栈空间的不够大的问题可以添加注释中的内容 #include<bits/stdc++.h> #...

天翼之城的博客 237

2019牛客暑期多校训练营(第六场)C - Palindrome Mouse (回文自动机)

https://ac.nowcoder.com/acm/contest/886/C 题意: 给出一个串A , 集合S里面为A串的回文字串 , 现在在集合S里面找出多少对(a,b),b为a的字串 分析:回文字串嘛,先盲猜一波回文自动机:我们现在知道回文自动机的原理图可以得出 , 它其实是用两棵树顶点为0和1 假设现在对于一个 XXXabccbaXXX 现在对于查到的点a 的贡献 ,...

weixin_30299539的博客 183

牛客多校2019-6C-Palindrome Mouse(回文自动机+统计支配点)

Palindrome Mouse 题意:若把给定字符串的所有不同回文子串放到一个集合内,求集合内有多少对回文子串满足其中一个是另一个的子串。 思路: 建好回文自动机 若设ansians_iansi​为回文树上能到达iii节点的节点数(0,10,10,1除外),则题目要求的就是∑i=2szansi\displaystyle\sum_{i=2}^{sz}ans_ii=2∑sz​ansi​ 那么如何统...

UniverseofHK的博客 423

回文树上dfs——牛客多校第六场C

/* set里的一定是本质不同的回文串,所以先建立回文树 当a可以通过nxt指针到达b,或者b可以通过fail指针到达a时,a就是b的子串 对于回文树里的每个结点u,我们可以将和其有关的结点为两部分: 1.结点下方的子树,这部分的所有结点都可以由u在两边加点得到,设大小为 size[u] 2.结点向上的fail链,这条链上的所有结点都是u的回文后缀,设大小...

weixin_30528371的博客 163

回文树(Palindrome Tree)/回文自动机(Palindrome Automaton)学习小记

简介回文树(回文自动机),是解决一类回文串问题的强大数据结构,比ManacherManacher扩展了很多功能。 这个数据结构比较新,由来自战斗民族的神犇MikhailRubinchik在2014年的Petrozavodsk夏令营提出。 这个数据结构代码量其实超级少。必备技能ManacherManacher 最好会至少一种自动机分析回文树严格来讲是由两棵树构成的森林,再加上一堆后缀链(失配链)

待成熟的葡萄 2973

2019杭电多校二 I Love Palindrome String(回文自动机)

题意 给定一个串,求各长度下,本质不同的回文串并且回文串的左右两个字串也是回文串的数量。 传送门 思路 题意比较绕,理顺下来就是在回文树的每个节点,求其节点对应回文串的一半是否也是回文串,如果是,则其对该节点的长度产生贡献, 判断其回文串的一半是否也为回文串可以用马拉车或者哈希,哈希相对好写一点。 回文树学习 Code #include <bits/stdc++.h> us...

diaozha3808的博客 174
上一篇: 2019牛客多校第三场 F.Planting Trees(单调队列)
下一篇: 强力输入挂
Cymbals
博客等级 码龄9年 45粉丝 157原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值