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

app下载更新 这是一个安卓app升级版本更新的项目,里面包含了通知栏更新以及app内部更新,更新的情况分为强制更新,推荐更新和无需更新3种,里面使用了downloaderManager和httpurlconnection的2种下载方式 立即下载
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);
}


ROS下UR+Realsense相机进行手眼标定 手眼标定主要是用来确定相机坐标系和机械臂坐标系之间的转换关系,从而实现后续的抓取等任务。 阅读详情

相关推荐

新手也能搞定!用ADS 2023从零设计一个超宽带Wilkinson功分器(附完整版图)

本文详细介绍了如何使用ADS 2023从零开始设计超宽带Wilkinson功分器,涵盖介质板参数设置、微带线计算优化、版图生成验证等关键步骤。通过实例演示和常见问题排查,帮助射频工程新手快速掌握功分器设计技巧,提升设计效率。

weixin_42692935的博客 476

Codeforces 696 D. Legen...

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

aisen1985的博客 213

手把手教你用Verilog实现MDIO控制器(附完整VHDL代码对比)

本文详细介绍了如何使用Verilog实现MDIO控制器,并提供了与VHDL实现的深度对比。通过解析MDIO协议核心要点,展示Verilog状态机架构设计和关键时序控制逻辑,同时对比VHDL在信号声明、状态机实现和双向端口处理上的差异。适用于以太网硬件设计开发者,帮助掌握MDIO控制器自主实现能力。

weixin_30682415的博客 422

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

kettle多表数据迁移

点击 文件——新建——作业,在左侧的 核心对象 标签下选择 通用,双击添加一个 start ,一个 转换 ,一个 作业 和一个 成功 到右侧的作业面板,这些作业项都可以改名字。点击文件—新建—转换,在左侧的 核心对象 标签下选择 输入 下的 表输入,双击添加到右侧的转换面板,再选择 作业 下的 复制记录到结果 ,双击添加到右侧的转换面板。新建转换,在左侧的 核心对象 标签下选择 作业 下的 从结果获取记录,双击添加到右侧的转换面板,再选择 作业 下的 设置变量 ,双击添加到右侧的转换面板。

u014061745的博客 1340

《深入浅出图神经网络:GNN原理解析》学习笔记

期末考完了,该上道了 目录一、图的概述1.基本概念2.图的存储和遍历3.应用分类二、神经网络基础1.机器学习2.神经网络三、卷积神经网络(CNN)1.卷积与池化2.卷积神经网络四、表示学习1.意义2.自编码器五、图信号处理与图卷积神经网络1.矩阵计算前置知识2.图信号与图的拉普拉斯矩阵3.图傅里叶变换4.图滤波器(Graph Filter)5.图卷积神经网络(GCN) 一、图的概述 1.基本概念 1.顶点(Vertex)表示研究的对象,边(Edge)表示两个对象之间特定的研究关系 2.图为顶点和边的集合.

且视他人之疑目如盏盏鬼火,大胆地去走你的夜路 2045

【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

一只酷酷光儿的博客 839

Unity 第一人称视角控制移动、旋转

第一人称视角操作此功能主要是借鉴YouTube,写的蛮好我就搬运过来让大家也试试。

qq_36515472的博客 4201

【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串翻转,处理

一只酷酷光儿的博客 665

别再只盯着YOLOv8了!手把手带你用PaddleDetection的PP-YOLOE+搞定你的第一个检测项目

本文介绍了PP-YOLOE+在目标检测领域的优势与应用实践,对比YOLOv8展示其在精度、速度和部署便利性上的突破。通过详细的代码示例和实战教程,帮助开发者快速上手PaddleDetection工具链,实现产业级目标检测项目,提升开发效率。

weixin_42701915的博客 184

Oracle EBS Interface/API(49)- AP付款取消API

Oracle EBS AP付款取消API介绍和简单实例

陈显平的专栏-Oracle EBS 849

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

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

KXL5180的博客 519

openclaw update时出现Skipped:this OpenClaw install isn‘t a git checkout,and the package manager解决方案

本文主要介绍了openclaw update时出现openclaw update时出现Skipped:this OpenClaw install isn’t a git checkout,and the package manager解决方案,希望能对使用openclaw的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 12万+

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

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

Miracle_ma的专栏 1290

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

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

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

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

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

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

dengliugong3918的博客 149

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的博客 581

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 305

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 510

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的博客 444

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

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

一只酷酷光儿的博客 579

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值