[Codeforces]696D Legen... AC自动机 + 矩阵快速幂

缠论中枢python源码_缠论分笔及中枢主图源码 HV1:=HHVV AND H>=HHV(H,BARSLAST(LLVV));LV1:=LLVV AND L<=LLV(L,BARSLAST(HHVV));DRAWLINE(LV1,LOW,HV1, HIGH,COLORYELLOW);DRAWLINE(HV1,HIGH,LV1, LOW,COLORMAGENTA); ///加入中枢判定//简化版N1:=10;N2:=10;DISP:=... 阅读详情
D. Legen...
time limit per test
6 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Barney was hanging out with Nora for a while and now he thinks he may have feelings for her. Barney wants to send her a cheesy text message and wants to make her as happy as possible.

Initially, happiness level of Nora is 0. Nora loves some pickup lines like "I'm falling for you" and stuff. Totally, she knows n pickup lines, each consisting only of lowercase English letters, also some of them may be equal (in writing, but different in pronouncing or meaning though). Every time Nora sees i-th pickup line as a consecutive subsequence of Barney's text message her happiness level increases by ai. These substrings may overlap, for example, Nora will see the pickup line aa twice and the pickup line ab once in text message aaab.

Due to texting app limits, Barney's text may have up to l characters.

Barney asked you to help him make Nora as much happy as possible, it's gonna be legen...

Input

The first line of input contains two integers n and l (1 ≤ n ≤ 200, 1 ≤ l ≤ 1014) — the number of pickup lines and the maximum length of Barney's text.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100), meaning that Nora's happiness level increases by ai after every time seeing i-th pickup line.

The next n lines contain the pickup lines. i-th of them contains a single string si consisting of only English lowercase letter. Summary length of all pickup lines does not exceed 200.

All strings are not empty.

Output

Print the only integer — the maximum possible value of Nora's happiness level after reading Barney's text.

Examples
input
3 6
3 2 1
heart
earth
art
output
6
input
3 6
3 2 8
heart
earth
art
output
16
Note

An optimal answer for the first sample case is hearth containing each pickup line exactly once.

An optimal answer for the second sample case is artart.

  

  大意就是说给定l和n个字符串, 每个字符串有一个分数, 求一个长度为l的字符串能获得的最大分数. 包含了给定字符串就能获得给定分数, 并且字符串之间可以重叠.

  给定长度的字符串, 包含xx串就... 这种类型的题已经很常见了... 一看就是要AC自动机上dp啊. 比如说设dp[i][j]表示从root出发走i步到了节点j此时能获得的最大分数. 这个dp很好转移. 到了有end节点就加分即可.

  但l太大显然dp不可过... 那么就只能上矩阵快速幂来优化辣... 矩阵a[i][j]表示从i走到j的最大分数. 矩阵乘法每乘一次可以看作走一步(这个可以详见POJ2778. 那么转移n次就可以了, 直接上快速幂. 这里矩阵不再是乘, 而是加和取max. 之所以能这样矩阵乘法是因为仔细想想可以发现从i走到j这样的路径这是可以拆开的... 其实你可以看成floyed的类似感觉.

  注意有重复串val要累加. 并且当前点也要累加fail的val(因为是后缀啊).

#include<bits/stdc++.h>
using namespace std;
typedef long long lnt;
const int maxn = 205;
char ss[maxn];
int m, tot;
lnt val[maxn], ans, n;
int w[maxn], c[maxn][26], fail[maxn];
inline void insert(int nw) {
	int p = 0;
	for (int i = 0; ss[i]; ++ i) {
		int idx = ss[i] - 'a';
		if (!c[p][idx]) c[p][idx] = ++ tot;
		p = c[p][idx];
	}
	val[p] += w[nw];
}
queue<int> q;
inline void bfs() {
	for (int i = 0; i < 26; ++ i)
		if (c[0][i]) q.push(c[0][i]);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = 0; i < 26; ++ i) {
			int &v = c[u][i];
			if (!v) {v = c[fail[u]][i]; continue;}
			fail[v] = c[fail[u]][i], val[v] += val[fail[v]];
			q.push(v);
		}
	}
}
struct Matrix {
	lnt mat[maxn][maxn];
	Matrix() {
		memset(mat, -1, sizeof (mat));
	}
	inline friend Matrix operator * (const Matrix &a, const Matrix &b) {
		Matrix c;
		for (int i = 0; i <= tot; ++ i)
			for (int k = 0; k <= tot; ++ k) if (~a.mat[i][k])
				for (int j = 0; j <= tot; ++ j) if (~b.mat[k][j])
					c.mat[i][j] = max(c.mat[i][j], a.mat[i][k] + b.mat[k][j]);
		return c;
	}
}a, ret;
int main() {
	scanf("%d%I64d", &m, &n);
	for (int i = 0; i < m; ++ i) scanf("%d", &w[i]);
	for (int i = 0; i < m; ++ i) {
		scanf("%s", ss);
		insert(i);
	}
	bfs();
	for (int i = 0; i <= tot; ++ i)
		for (int p = 0; p < 26; ++ p) {
			a.mat[i][c[i][p]] = val[c[i][p]];
		}
	ret = a, -- n;
	while (n) {
		if (n & 1) ret = ret * a;
		a = a * a, n >>= 1;
	}
	for (int i = 0; i <= tot; ++ i)
		ans = max(ans, ret.mat[0][i]);
	printf("%I64d\n", ans);
}


蓝桥杯 stm32 PWM 测量频率 参考 数据手册:比赛 的板子 上面有两个信号发生器,如下图。通过 扭动 可变电阻 (R40, R39), 来实现 PWM 频率的改变。PA15PB4。PA15,PB4分别使用TIM2_CH1TIM3_CH1来对频率进行捕获。 阅读详情

相关推荐

Windows环境Oracle19C安装与配置全攻略

本文详细介绍了在Windows环境下安装与配置Oracle19C数据库的完整流程,包括环境准备、安装步骤、网络配置、客户端工具设置及常见问题解决方案。特别针对Windows 10和Windows Server 2016及以上版本提供了优化建议,帮助用户高效完成Oracle19C的部署与维护。

weixin_28455801的博客 494

Codeforces 696 D. Legen...

Description 每个字符串有些价值,问生成长度为 \(l\) 的字符串最多能获得多少价值,总字符数不超过 \(200\), \(l\leqslant 10^{14}\) . Sol AC自动机 + 倍增Floyd. 用AC自动机统计到达每个节点会获得的权值. 然后在AC自动机从根节点开始找一条最长路,就用Floyd倍增就可以了... 发现自己AC自动机做Fail树的时...

aisen1985的博客 214

流媒体学习之路(mediasoup)——simulcast 与 svc 简介(7)

流媒体学习之路(mediasoup)——simulcast 与 svc(7) 文章目录流媒体学习之路(mediasoup)——simulcast 与 svc(7)

qw225967的博客 7348

Codeforces Round #362(Div1) D Legen...(AC自动机+矩阵快速幂)

题目大意: 给定一些开心串,每个串有一个开心值,构造一个串,每包含一次开心串就会获得一个开心值,求最大获得多少开心值。 题解: 首先先建立AC自动机。(建立fail指针的时候,对val要进行累加) 然后在AC自动机上跑dp dp[i][j] = max(dp[i][j], dp[i-1][k] + v[j]) 写成矩阵形式就是(Mat[i][j]表示从i到j最大获得的开心值) ...

weixin_34402090的博客 169

C++笔试题整理

目录 1. 笔试题1 1.1 链表反转 1.2 String 2. 笔试题2 2.1 求下面函数的返回值(微软) 2.2 什么是“引用”?申明和使用“引用”要注意哪些问题? 2.3 将“引用”作为函数参数有哪些特点? 2.4 在什么时候需要使用“常引用”?  2.5 将“引用”作为函数返回值类型的格式、好处和需要遵守的规则? 2.6 “引用”与多态的关系? 2.7 “引用”与指针的区别是什么? 2.8 什么时候需要“引用”? 2.9 结构与联合有和区别? 2.10 下面关于.

星月相随的专栏 2490

NOAA气象数据下载攻略

各方搜寻气象数据下载途径,发现网上最多的就是从NOAA下载,但是中途有尝试过很多次都没有下载到,每次都是显示不可用,今天终于下载成功了,特此记录。 首先我是从这个网址进入的:National Centers for Environmental Information (NCEI) formerly known as National Climatic Data Center (NCDC) | NCEI offers access to the most significant archives of oc

lianqian66的博客 3万+

【Codeforces 1163D】Mysterious Code | AC自动机、fail树上dp

题目链接:https://codeforces.com/contest/1163/problem/D 题目大意: 首先定义f(s,t)函数,表示t中含有s串个数 之后首先给出一个c串,由'*'和小写字母组成,其中'*'可以替换为26个字母中的任意一个 之后给出两个串s,t。 要求你根据c串中的'*'构造c串使得f(s,c) - f(t,c)最大 题目思路: 多字符串包含关系必然会想到AC自动机 首先考虑,建立AC自动机时,节点得权值情况 在字典树上s的终结点权值为1,t的终结点权值为-1

一只酷酷光儿的博客 845

DCA1000EVM数据采集实战:从mmWave Studio配置到MATLAB后处理的全链路解析

本文详细解析了DCA1000EVM数据采集的全流程,从mmWave Studio配置到MATLAB后处理,涵盖数据存储结构解析、后处理引擎剖析及Python数据处理方案。通过实战案例,帮助开发者高效处理毫米波雷达原始数据,实现从数据到应用价值的转化,提升开发效率。

weixin_33743661的博客 714

【Codeforces 149E】Martian Strings | KMP、AC自动机

想刷下AC自动机的题,搜出来个这个 但是用KMP过了.. 题目链接:https://codeforces.com/contest/149/problem/E 题目大意: 给出一个t串,和m个s串,对于每个s串判断是否可以在t串中找出两个子串 使得T[a,b] + T[c,d] = s 输出所有可以的s串的个数 题目思路: Thinking_1 嗯...稍后会更新AC自动机的写法 考虑kmp,pre_i代表s串前缀与t串前i个前缀匹配的最大长度 预处理好pre数组之后 将s串翻转,处理

一只酷酷光儿的博客 673

深度解析机器人关节位置环控制:从理论到实践

本文系统阐述了机器人关节位置环控制的核心原理与实现方法。首先介绍了关节控制的基础框架,阐明位置环在闭环控制中的关键作用。随后深入解析PID控制算法原理,包括比例、积分、微分项的功能与参数整定原则。在软件实现部分,提供了模块化设计思路和Python伪代码示例,强调实时性保障和异常处理机制。文章还包含典型面试问题解答和应用案例,展示如何通过参数优化将定位精度提升20倍。最后指出未来发展趋势将聚焦算法自适应性和系统稳健性。全文兼顾理论深度与实践指导,为开发者提供从基础到进阶的完整技术路线图。

郑伟强dev的专栏 56

STM32(HAL库)驱动OLED

通过STM32F103C8T6单片机采用HAL库方式对0.96寸OLED(IIC通讯)屏幕进行驱动。

weixin_44597885的博客 8819

Codeforces 163E (AC自动机&fail树+dfs序+树状数组)

http://codeforces.com/contest/163/problem/E 实在不好意思,自己画的时候确实有点粗心,感谢大家的提醒。。这次图应该画对了。。 题意:给你几个串,然后后面有些操作,分别是给你一个文本串问哪些模式串在文本串出现了多少次,剩下两个分别就是删除一些字符串,和恢复一些字符串。 做法:AC自动机,(据说还有后缀数组。。不会),如果做过阿狸的打字机这道题应该知道怎...

KXL5180的博客 521

wireshark提取视频数据之RTP包中提取H264和H265

本文主要描述从wireshark包数据中提取出H264和H265裸流数据方法,裸流通过RTP封包方式发送,从抓包中直接提取视频流数据,进而进行流媒体问题定位

技术控的笔记 17万+

Codeforces 696D Legen...(AC自动机+矩阵快速幂)

http://codeforces.com/problemset/problem/696/D题意:给你n个串,每个串有个开心值,然后让你构造一个长为l的串,使得开心值之和最大。 题解:AC自动机处理这些串,然后开心值加在终止节点上,可能同一个节点有多个串,开心值就要加起来,然后bfs建立trie图的时候,要把失配之后的节点的开心值也要加到这个节点上,这样就不会漏掉了。 然后对于矩阵的每个节点i,

Miracle_ma的专栏 1291

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

深度学习工具包 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 696D Legen... AC自动机 + 矩阵快速幂

Legen... 我们能很容易写出在AC自动机上的dp, dp[ k ][ i ][ j ]表示走了 k 步从 i 走到 j 的最大值。 k 很大我们考虑矩阵优化, 直接搞就好啦。 不知道为什么在本机上M * M * M * M **** * M 打多了就会卡死不知道为什么。。。 #include<bits/stdc++.h> #define LL long long ...

weixin_30628801的博客 143

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Codeforces 696D Legen...(AC自动机 + 矩阵快速幂)

题目大概说给几个字符串,每个字符串都有一个开心值,一个串如果包含一次这些字符串就加上对应的开心值,问长度n的串开心值最多可以是多少。 POJ2778。。复习下。。太弱了都快不会做了。。 这个矩阵的乘法定义是不同的,m[i][j]=max(m1[i][k]+m2[k][j]),即从i走到k能获得的最大值与从k走到j能获得的最大值之和去更新从i到j能获得的最大值。 另外。。关于矩...

dengliugong3918的博客 149

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

CodeForces 696D Legen...(AC自动机+矩阵快速幂)

CodeForces 696D Legen…原题地址:http://codeforces.com/problemset/problem/696/D题意: Barney爱上了Nora 想发给她一段长为ll的话(一个由小写字母组成的串)让她开心一下。 Nora有n个喜欢的话(例如 I’m falling for you 这种情话。当然,给出的都是由小写字母组成的串),每个串ii有一个开心值aia_i

Bfk的博客 583

codeforces 696D Legen...(AC自动机+矩阵快速幂)

696D Legen... 题意:n个字符串(价值val[i]),请构造长度为l的字符串,使它的价值最大(子串的价值之和)。 题解: 配合 POJ 2778食用。 http://blog.csdn.net/qq_32707623/article/details/54574281 这题要搞清楚End数组的含义(以该节点结束的字符串的价值)。 还

417

CodeForces - 696D:AC自动机 + 矩阵快速幂

CodeForces - 696D 题解 ​​如果一个串s1包含于另一个串s2,那么val[s2] += val[s1]。即统计每个串所包含的所有字串和本身的值的和。 初始化矩阵,结点s1连向另外一个结点s2,权值为s2的值。表示s1可以一步到达s2。最后L个矩阵相乘,表示一个结点可以经过L步到达另一个结点。我们要找root结点经过L步可以到达的权值最大的结点。 注意矩...

FlyingJack 306

CodeForces 696D AC自动机+DP+矩阵快速幂

题意给一组字符串,每个字符串有一个值,如果一个字符串包含这个子串,那么总值就加上这个子串的值。给一个长度,问能组成的最大值。题解对于要求长度1000的情况,我们可以直接DP。但是这道题不 行,这道题长度达到了10^16。我们考虑用矩阵快速幂加速。 我们很容易便能得到一个状态转移方程,dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j])。这个状态转移方程中的I,J,K都

zhenlingcn的博客 433

[CodeForces 697F][CodeForces 696D] Legen...(AC自动机+矩阵加速)

文章目录题目分析代码 题目 time limit per test: 6 seconds memory limit per test: 256 megabytes input: standard input output: standard output Description Barney was hanging out with Nora for a while and now he thin...

ixRic 511

CodeForces - 697F Legen... AC自动机+快速幂

题目链接点这里 这题很好,很强大,做了一晚上。。。。 如果对这题毫无思路的,建议先坐下这道题。做完这道题,结合10^14的数据,应该可以想到本题也应该利用AC自动机构造状态转移矩阵,然后利用快速幂加速 不过这里的矩阵乘法定义为  M[i][j]=max(a[i][k]+b[k][i],M[i][j]); #include #include #include #include #includ

我们做的队 694

codeforces 1163D(AC自动机dp)

题意:给定一个文本串,两个模式串,将文本串的*替换为26个 字母,使得第一个模式串出现的次数减去第二个模式串出现的次数的差值最大。 思路:fail树的应用 我们对两个模式串建立AC自动机,并计算出每个状态的权值。每个状态的权值定义为其fail树上一直到根节点的权值之和。原因为走到这个节点,就相当于到根节点路径上的的所有前缀都已经访问过了。 #include &l...

ehdhg13455的博客 446

【Codeforces 1437G】Death DBMS | AC自动机fail树上树链剖分

题目连接:https://codeforces.com/contest/1437/problem/G 题目大意: 首先给出一个数据库,数据库中包含n个字符串 接下来支持两个操作: 1.将第i个字符串的权值改为w 2.询问字符串q中,包含的所有在数据库中的字符串中的最大权值(起初取值为0),如果没有包含数据库中的字符串输出-1 题目思路: 一个很明显的思路: 用AC自动机将fail树建立起来 有了fail树之后,对于询问串的每一个位置,从第一次能匹配到的位置开始到根节点的最大值,就是以该位置

一只酷酷光儿的博客 585

Codeforces Round #696 (Div. 2)部分题解

Codeforces Round #696 (Div. 2) D. Cleaning 思路:思维 我们首先考虑不用交换时解题的步骤: (1) 对于第一个元素a1, 想要清除a1就只有当第二个元素a2 > a1时,a1为0,此时第二个元素变为a2 - a1,否则算法退出,不能消除全部元素。 (2)将第二个元素a2 - a1 看作第一个元素,那么想要消除它就只有当第三个元素 a3 > a2 - a1 时,a2 - a1 为0, 此时第三个元素变为 a3 - (a2 - a1),否则算法退出,不能消除

qq_43569892的博客 255

【题解】Codeforces 963D. Frequency of String AC自动机

给定字符串S(1e5)S(1e5)S(1e5),有q(1e5)q(1e5)q(1e5)个询问,每次给定一个整数kik_iki​和字符串mim_imi​。 让你从SSS中选择一个子串TTT,且mim_imi​在TTT中出现了至少kik_iki​次。 保证mim_imi​的长度之和不超过1e51e51e5,保证所有的mim_imi​不相同。 这道题的关键在最后的两个保证上。 使用AC自动机可以求得所......

秋叶红于二月花 686
上一篇: [BZOJ]3238 差异 后缀树
下一篇: 博客申明
MaxMercer
博客等级 码龄10年 55粉丝 261原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值