[AC自动机+dp]PKU 3691--DNA repair

存储硬盘格式怎么把512还原为520格式?? 硬盘厂商工具(如SeaChestsg_format)可以调整扇区大小。备份数据,因为调整扇区会清除硬盘内容。根据硬盘型号和接口类型,选择合适的工具进行调整。如果你需要更详细的帮助,请提供你的硬盘型号和存储设备类型。希望如上措施及解决方案能够帮到有需要的你。PS:如若遇到采纳如下方案还是未解决的同学,希望不要抱怨&&急躁,毕竟影响因素众多,我写出来也是希望能够尽最大努力帮助到同类似问题的小伙伴,即把你未解决或者产生新Bug黏贴在评论区,我们大家一起来努力,一起帮你看看,可以不咯。 阅读详情
DNA repair
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 1469 Accepted: 650

Description

Biologists finally invent techniques of repairing DNA that contains segments causing kinds of inherited diseases. For the sake of simplicity, a DNA is represented as a string containing characters 'A', 'G' , 'C' and 'T'. The repairing techniques are simply to change some characters to eliminate all segments causing diseases. For example, we can repair a DNA "AAGCAG" to "AGGCAC" to eliminate the initial causing disease segments "AAG", "AGC" and "CAG" by changing two characters. Note that the repaired DNA can still contain only characters 'A', 'G', 'C' and 'T'.

You are to help the biologists to repair a DNA by changing least number of characters.

Input

The input consists of multiple test cases. Each test case starts with a line containing one integers N (1 ≤ N ≤ 50), which is the number of DNA segments causing inherited diseases.
The following N lines gives N non-empty strings of length not greater than 20 containing only characters in "AGCT", which are the DNA segments causing inherited disease.
The last line of the test case is a non-empty string of length not greater than 1000 containing only characters in "AGCT", which is the DNA to be repaired.

The last test case is followed by a line containing one zeros.

Output

For each test case, print a line containing the test case number( beginning with 1) followed by the
number of characters which need to be changed. If it's impossible to repair the given DNA, print -1.

 

Sample Input

2
AAA
AAG
AAAG    
2
A
TG
TGAATG
4
A
G
C
T
AGT
0

Sample Output

Case 1: 1
Case 2: 4
Case 3: -1
题目大意:给出一个字符串和若干个非法子串,求最少修改字符串中的多少个字符可以使得字符串中不存在非法子串。

分析:若字符串是01串,若子串长度为10,可以用经典的状态压缩dp解决,即:f[i,j]表示前i个,前9个数字状态为j的最小修改次数。然而,本题数据规模大得多,不能用这个dp。

我们来分析一下状态,对于以下的这个输入:

AAA

GT

XXXXXX

TC、AT、CT之类的状态其实都是一样的。

这些状态都是什么呢?

有穷状态自动机上的某些节点。

我们只要对所有的非法子串,构建一个AC自动机,那么自动机上的某个节点即为一类状态。

所以得到以下动态规划算法:

令f[i,j]表示对于字符串中的前i位,使得状态为自动机上的节点j,期间不经过任何一个非法子串需要修改的最少字符数。

则f[i,j]=min(f[i-1,k]+(1-ord(s[i]=way[k,j])))。其中,k为j的父亲节点(不一定是直接的父亲),way[k,j]为k连向j的边所代表的字母。这个转移方程不难理解,若第i位和边的字符不同,需要修改,答案+1,否则不用。答案便是max(f[len,i]),i不为某个非法子串的最后一个字母。

另外,在构建失败指针的同时,若某个节点的某个儿子为空,则要通过失败指针找到一个儿子,不然指向根。

具体的参看程序。

 

codes:

 

 

大疆司空 2 私有化部署:FH2、Terra、4G 三大服务区别详解 摘要: 司空2私有版包含三大模块:FH2(核心平台,必选)、Terra(建模算力,需NVIDIA显卡)、4G(内网图传)。FH2是基础,支持设备管理与任务调度;Terra适用于测绘建模场景,依赖GPU算力;4G模块保障复杂环境下的图传稳定性,适合纯内网部署。选择逻辑:先部署FH2,再按需添加Terra(需显卡)或4G(需内网支持),避免资源浪费。 阅读详情

相关推荐

别再乱用标签了!深度解析Unity Addressables标签(Labels)的三种高级用法与性能影响

本文深度解析Unity Addressables标签(Labels)的三种高级用法与性能影响,包括标签组合查询、Pack Together by Label打包策略及运行时性能优化。通过实战代码示例和性能数据对比,帮助开发者实现精细化资源加载控制与包体优化,提升项目效率。

weixin_30500105的博客 509

pku 3691 DNA repair AC自动机——DP

http://poj.org/problem?id=3691 题意: 给出n个DNA病毒串,然后给出一个需要修改的DNA片段,问需要最少修改多少个字符才能是该DNA片段不含DNA病毒串,修改后的DNA片段长度不变 思路:这题看了一天了,DP那地方好难懂。首先这里是多串匹配,我们用Trie树和fail的构造确定性有限状态自动机(DFA),然后再DFA上进行DP; 这里我DP理解了很长时间,d...

weixin_30608131的博客 63

SuperPoint+SuperGlue在HLoc中的实战效果对比:5大公开数据集测试报告

本文在HLoc框架下,对传统SIFT与深度学习组合SuperPoint+SuperGlue在五大公开数据集上的视觉定位效果进行了实战对比测试。报告详细分析了两种方案在Aachen Day-Night、RobotCar Seasons等不同光照、季节及场景下的表现,揭示了SuperPoint+SuperGlue在应对剧烈光照变化和长期外观变化时的显著优势,并提供了基于HLoc模块化设计的选型与配置策略。

weixin_29093169的博客 425

[PKU/POJ][3691][DNA repair][AC自动机+DP]

先用AC自动机构建一个不含有任何病毒串的 DFA , dp[i][j] 表示到目标串的第 i 个字符,DFA 状态为 j 时的最小修改数量。则 dp[i][ son[j] ]= min{ dp[i][ son[j] ], dp[i-1][j]+ (tran[j][ son[j] ]!= str[i] ) }  tran[j][ son[j] ]表示从 j 到 son[j] 经过的字母边。 代码:...

信仰 忍耐 120

Unity UI适配实战:从Canvas Scaler到主流游戏适配方案解析

本文深入解析Unity UI适配的核心技术,重点介绍Canvas Scaler组件的关键参数如Reference Resolution和Screen Match Mode,并提供主流游戏适配方案实战分析。通过九宫格拉伸、动态调整等技巧,帮助开发者解决多设备适配难题,提升游戏UI在不同分辨率下的表现。

weixin_29001419的博客 972

单精度浮点数存储、双精度浮点数存储

单精度浮点数存储、双精度浮点数存储

fancynthia的博客 1312

HDU 2457 DNA repair(AC自动机+DP)题解

题意:给你几个模式串,问你主串最少改几个字符能够使主串不包含模式串 思路:从昨天中午开始研究,研究到现在终于看懂了。既然是多模匹配,我们是要用到AC自动机的。我们把主串放到AC自动机上跑,并保证不出现模式串,这里对AC自动机的创建有所改动,我们需要修改不存在但是符合要求的节点,如果某节点的某一子节点不存在,我们就把这个子节点指向他父辈节点存在的该节点(比如k->next[1]不存在,k-&...

努力,奋斗 351

【UE5】三步搞定Pixel Streaming:从零搭建Windows像素流服务

本文详细介绍了如何在Windows平台上快速搭建UE5 Pixel Streaming像素流服务,从插件安装、项目打包到服务启动的全流程操作。通过实战案例和优化配置,帮助开发者实现零客户端配置、跨设备兼容的高性能3D应用流式传输,特别适合建筑可视化和实时协作场景。

weixin_29000991的博客 318

noi2004-郁闷的出纳员(cashier) 解题报告

  NOI2004郁闷的出纳员【问题描述】 OIER公司是一家大型专业化软件公司,有着数以万计的员工。作为一名出纳员,我的任务之一便是统计每位员工的工资。这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常调整员工的工资。如果他心情好,就可能把每位员工的工资加上一个相同的量。反之,如果心情不好,就可能把他们的工资扣除一个相同的量。我真不知道除了调工资他还做什么其它事情。

幻想の天地 2051

46、大数据助力SDN优化流量管理与控制器

本文探讨了大数据在软件定义网络(SDN)中的应用,重点分析了如何利用大数据技术优化SDN控制器的可扩展性和弹性。通过介绍SDN控制器的核心功能及其面临的挑战,提出了集中式、分布式、混合式和分层式控制器放置策略,并结合大数据分析系统架构与技术,详细阐述了在控制器放置优化、流聚合和备份路径识别等场景中的实际应用。文章还给出了大数据分析在SDN控制器优化中的操作流程与优势,展望了未来结合人工智能与物联网的发展方向,强调了数据安全与算法效率的重要性。

xx56789的博客 86

Sigrity System Explorer Transient Analysis模式进行瞬态仿真分析操作指导-单端信号

Sigrity System Explorer Transient Analysis模式可以用于瞬态仿真分析,通过搭建简易拓扑用于前仿真分析通道的时域性能,下面搭建一个简易的单端拓扑进行说明,以下图为例,准备好发送接收端的IBIS模型, (ibis_se.ibs,本例发送接收端都使用相同的IBIS模型),以及传输线的S参数模型(welement_se.sp)最上方的图形界面是传输线的模型,本例是一个上下都有参考平面的带状线,右侧的梯形是蚀刻角度,根据W1和W2以及铜厚来确定。

weixin_54787054的博客 417

[动态规划]Pku2411--Mondriaan's Dream

Mondriaans DreamTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 3732 Accepted: 2156DescriptionSquares and rectangles fascinated the famous Dutch painter

幻想の天地 2022

仅使用 Python 创建的 Web 应用程序(前端版本)第03章Streamlit-多页面

接下来,我们将解释多页面切换。Streamlit 没有“多页面”或“页面路由”等功能。另一方面,通过根据用户动作切换要执行的功能,可以使其看起来好像存在“多个页面”。注意:我认为它类似于 SinglePageApplication (SPA)。然而,根据 React、Vue 等中使用的 URL 路径来更改页面的路由很困难。还有一个用于获取查询参数的实验性 API,但如果您确实需要这种功能,我认为认真尝试编写 React 或 Vue 是个好主意。我们来看一个通过按下按钮来切换页面的示例,如下所示。

xianyinsuifeng的博客 1329

[动态规划+矩阵快速幂优化]Pku3420--Quad Tiling

Quad TilingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1801 Accepted: 698DescriptionTired of the Tri Tiling game finally, Michael turns to a more

幻想の天地 1385

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对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")

[ac自动机]zoj3228 Searching the String

Searching the StringTime Limit: 7 Seconds      Memory Limit: 129872 KB Little jay really hates to deal with string. But moondy likes it very much, and shes so mischievous that she often gives

幻想の天地 1366

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

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

Pku1037 A decorative fence 动态规划+递推

A decorative fenceTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3468 Accepted: 1122DescriptionRichard just finished building his new house. Now the only

幻想の天地 1354

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

[数学-欧拉函数]Pku2478--Farey Sequence

http://acm.pku.edu.cn/JudgeOnline/problem?id=2478 Farey SequenceTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5575 Accepted: 1998DescriptionThe Fare

幻想の天地 1056

[动态规划]Pku1390 Blocks

BlocksTime Limit: 5000MS Memory Limit: 65536KTotal Submissions: 1497 Accepted: 567DescriptionSome of you may have played a game called Blocks. There are n blocks

幻想の天地 971

[数学-farey序列]Pku3374--Cake Share

http://acm.pku.edu.cn/JudgeOnline/problem?id=3374 Cake ShareTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2836 Accepted: 700DescriptionUpdog pre

幻想の天地 947

[动态规划,tsp问题]pku2288 Islands and Bridges

Islands and BridgesTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 4173 Accepted: 1008DescriptionGiven a map of islands and bridges that connect these isl

幻想の天地 920

[AC自动机]hdu2222 Keywords Search

Keywords SearchTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3406    Accepted Submission(s): 1177Problem DescriptionIn

幻想の天地 898

[动态规划]Zju1234--Chopsticks

ChopsticksTime Limit: 10 Seconds      Memory Limit: 32768 KB In China, people use a pair of chopsticks to get food on the table, but Mr. L is a bit different. He uses a set of three chopsticks

幻想の天地 818

[动态规划]Pku3377--Ferry Lanes

http://acm.pku.edu.cn/JudgeOnline/problem?id=3377 Ferry LanesTime Limit: 2000MS Memory Limit: 131072KTotal Submissions: 2563 Accepted: 510Description

幻想の天地 770

vijos 不差钱 sbt的运用

 不差钱Buchaqian.pas描述:同学们一起看了小品《不差钱》,LX神突发奇想,想刁难一下十八居士,他让十八居士模拟一下点菜的过程。 输入:第一行为一个数price,表示价钱大于price的菜赵本山都不要。以下几行表示点菜的过程,每行两个整数p,np=1 表示在菜谱中添加一个价格为n的菜,这是第i个1号命令,这个菜的编号就是i,p=2 表示菜谱中第n号菜已

幻想の天地 763

[最短路spfa]pku1511-Invitation Cards

http://acm.pku.edu.cn/JudgeOnline/problem?id=1511 Invitation CardsTime Limit: 8000MS Memory Limit: 262144KTotal Submissions: 5784 Accepted: 1616DescriptionIn th

幻想の天地 713
上一篇: [ac自动机]zoj3228 Searching the String
下一篇: [计算几何-凸包]pku1113-Wall
fstephen
博客等级 码龄18年 7粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值