最长公共子串与最长公共子序列

动态规划经典问题 - 求最长公共子串 / 公共子序列 首先要理解公共子串和公共子序列 公共子串和公共子序列是两个不相同的概念, 公共子串要求字符连续, 公共子序列不要求字符连续。 比如: 字符串"ascde", “axcxdde” 最长公共子串是 “de” , 因为 "de"在两个字符串中都是连续的 最长公共子序列是 “acde”, 不要求连续, 只要满足两个字符串中子序列前后顺序的一致即可 动态规划求最长公共子序列 动态规划的核心是 base case 状态转移方程 自下而上 我们可以通过状态转移表来帮助我们得出状态转移方程 这里我直接说结论: 我们思考 阅读详情

1. 最长公共子串

要求子串连续,不同于最长公共子序列

def LCS(s1, s2):
    len1, len2 = len(s1), len(s2)
    # 匹配矩阵,用来记录两个字符串中所有位置的两个字符之间的匹配情况(1:匹配;0:不匹配)
    c = [[0 for j in range(len2+1)] for i in range(len1+1)]
    n = 0  # 最长匹配长度
    p = 0  # 匹配的结束位置的下一位
    for i in range(1, len1+1):
        for j in range(1, len2+1):
            if s1[i-1] == s2[j-1]:
                c[i][j] = c[i-1][j-1]+1
            if c[i][j] > n:
                n = c[i][j]
                p = i
    print("最长子串:  ", s1[p-n: p])
    print("最长子串长度:  ", n)

测试

s1 = 'hello boy, good night'
s2 = 'hi boy, good good night'
LCS(s1, s2)
# 最长子串:    boy, good 
# 最长子串长度:   11

2. 最长公共子序列

def LCS_squence(s1, s2):
    len1, len2 = len(s1), len(s2)
    # 匹配矩阵,用来记录两个字符串中所有位置的两个字符之间的匹配情况(1:匹配;0:不匹配)
    c = [[0 for j in range(len2+1)] for i in range(len1+1)]
    for i in range(1, len1+1):
        for j in range(1, len2+1):
            if s1[i-1] == s2[j-1]:
                c[i][j] = c[i-1][j-1]+1
            else:
                c[i][j] = max(c[i-1][j], c[i][j-1])
    print("最长公共子序列长度:  ", c[-1][-1])

    i, j = len1, len2
    result = []
    while c[i][j]:
        if c[i][j] == c[i-1][j]:
            i -= 1
        elif c[i][j] == c[i][j-1]:
            j -= 1
        elif c[i][j] > c[i-1][j-1]:
            i -= 1
            j -= 1
            result.append(s1[i])
    print("最长公共子序列长度:  ", ''.join(result[::-1]))

测试

s1 = 'hello boy, good night'
s2 = 'hi boy, good good night'
LCS_squence(s1, s2)
# 最长公共子序列长度:   17
# 最长公共子序列长度:   h boy, good night

3. DP问题思路分析

对于X=(A,B,C,B,D),Y=(B,D,C,A,B)两者最长公共子序列构成路径表。

 可用动态规划DP求解的问题一般有两个特征:

1. 最优子结构;

2. 重叠子问题。

3.1 最优子结构

        设X=(x1,x2,x3,...,xm),Y=(y1,y2,y3,...,yn),求X和Y的最长公共子序列LCS(X,Y),就是一个最优化问题,首先考虑X的最后一个元素xm与Y的最后一个元素yn。

LCS(X, Y) = LCS(Xm-1, Yn-1)       if xm=yn

LCS(X, Y) =max(LCS(Xm-1, Yn), LCS(Xm, Yn-1))       if xm != yn

把原问题转化成了三个规模更小的子问题。

3.2 重叠子问题

        在问题的继续分解中,有些问题是重叠的,若用递归求解,将有指数级个子问题,故时间复杂度是指数级,而使用DP,可以用一张表记录子问题的解。

LCS的递推式如下:

c[i][j] = 0                        if i=0 or j=0

c[i][j] = c[i-1][j-1]+1       if i,j>0, xi=yj

c[i][j] = max(c[i][j-1], c[i-1][j])     if i,j>0, xi!=yj

c[i][j] = len(lCS(Xi, Yj)) 表示两个序列X和Y的最长公共子序列长度。

动态规划---最长公共子序列和最长公共子串 说到动态规划,不得不说到经典的最长公共子序列(Longest Common Sequence)问题和最长公共子串(Longest Common Substring),都被称为LCS问题 其中最长公共子串是最长公共子序列的衍生问题,我们今天来重点讨论一下这两个问题。 首先我们先区分一下最长公共子序列和最长公共子串,直接举一个例子就能明白。比如给你两个字符串分别数adminos和admins,请问它们的最长公共子序列和最长公共子串分别是什么嘞? 最长公共子序列:admins 最长公共子串:admin 通过比较, 阅读详情

相关推荐

动态规划:求最长公共子串/最长公共子序列

最长公共子序列和最长公共子串区别        最长公共子串(Longest Common Substring)与最长公共子序列(Longest Common Subsequence)的区别: 子串要求在原字符串中是连续的,而子序列则只需保持相对顺序一致,并不要求连续。例如X = {a, Q, 1, 1}; Y = {a, 1, 1, d, f}那么,{a, 1, 1}是X和Y的最长公共子序

Sunshine的专栏 3万+

数据结构与算法之最长公共子串

最长公共子串问题是指给定两个字符串S1和S2,求它们的公共子串中最长的那一个。其实就是求两个字符串的最长重复子串。最朴素的算法就是枚举S1和S2的每一对子串,然后判断它们是否相等,时间复杂度是O(n^3)。但是这种算法效率太低,无法满足实际需求。一般采用动态规划的思想进行求解,令dp[i][j]表示以S1的前i个字符和S2的前j个字符为结尾的公共子串的长度,当S1[i]=S2[j]时,dp[i][j]=dp[i-1][j-1]+1;否则dp[i][j]=0。最后找出dp[i][j]的最大值即可。

weixin_47225948的博客 4925

【LeetCode】最长公共子串&最长公共子序列

子序列与子串的区别: 假设有S1 = “abcdeffg” S2 = "abcfg" 子串:“abc” 子序列:“abcfg” 简单的说,子串就是需要连续,子序列不需要连续。 题目1:子串 可能我这么说不严谨,其实718题是子数组,但意思是一样的,都是需要找连续的。 718. 最长重复子数组 给两个整数数组A和B,返回两个数组中公共的、长度最长的子数组的长度。 示例 1:...

Max的专栏 5263

最长公共子串

最长公共子串

weixin_53235736的博客 3980

最长公共子序列(LCS)和最长公共子串长度DP算法

leetCode最长公共子序列问题地址:https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/comments/ 描述 给两个整数数组 A 和 B ,返回两个数组中公共的、长度最长的子数组的长度。 使用动态规划算法 推荐一篇好理解的文章 使用到的关键点: 初始化DP二维数组 DP二维数组填充的值对应的公式 ...

RuiDer的博客 1925

最长公共子串(动态规划)

来源:https://www.cnblogs.com/fanguangdexiaoyuer/p/11281179.html1 描述 有两个字符串(可能包含空格),请找出其中最长的公共连续...

编程与实战的博客 2258

最长公共子序列(LCS) 最长公共子串

1.最长公共子序列 什么是子序列: 例如对于字符串"saabcd",s,a,a是其一个子序列,s,a,b,d也是一个子序列。子序列不要求连续性。 最长公共子序列问题有最优子结构,这个问题可以分解称为更小的问题,因此整个问题就变简单了。同时,子问题的解释可以被重复使用的,也就是说更高级别的子问题会重用更小子问题的解。满足这两点以后,很容易就想到用动态规划来求解。 1.假设两个字符串s1, s2。当其...

bitcarmanlee的博客 1万+

量子密钥分发系统的设计与实现(二):光路子系统初步讨论

本文主要对量子密钥分发系统中的光路子系统方案进行了讨论。

量子领域相关话题 2407

最长公共子序列、最长公共子串的输出

1、最长公共子序列: 举个例子,s1=“abcfde”,s2=“fdea”。那么s1与s2的最长公共子序列就是"fde"。该问题是典型的动态规划问题,我们设maxlen(i,j)表示s1左边i个字符与s2左边j个字符的最长公共子序列长度,(i,j)从0开始,那么递推关系很容易找到,就是: if(s1[i-1]==s2[j-1]) { maxlen(i,j)=maxlen(i-1,j-1)+1; }else { maxlen(i,j)=max(maxlen(i,j-1),maxlen(i-1,j)

KI的博客 8万+

Ubuntu中snap简单介绍

通过Snap可以安装众多的软件包。需要注意的是,snap是一种全新的软件包管理方式,它类似一个容器拥有一个应用程序所有的文件和库,各个应用程序之间完全独立。所以使用snap包的好处就是它解决了应用程序之间的依赖问题,使应用程序之间更容易管理。但是由此带来的问题就是它占用更多的磁盘空间 介绍一些常用命令,有点类似docker 1、查看已经通过snap安装的snap包 snap list可以查看 2、可以搜索想要的snap包,例如tomcat snap search tomcat

icanflying的博客 4万+

从零开始:手把手教你用VOACAP软件预测短波最佳工作频率(OWF)

本文详细介绍了如何使用VOACAP软件预测短波通信的最佳工作频率(OWF),涵盖软件安装、参数配置、电离层模型设置及结果解读。通过实战案例和优化技巧,帮助用户掌握短波传播特性,提升通信效率。特别适合业余无线电爱好者和专业通信人员参考。

weixin_30897079的博客 649

最长公共子序列和最长公共子串的动态规划实现(java)

最长公共子序列和最长公共子串的动态规划算法实现,java代码以及个人见解。

晓茸有点甜的博客 7063

Halcon实战:5分钟搞定线序颜色检测(附完整代码解析)

本文详细介绍了如何使用Halcon在5分钟内实现工业级线序颜色检测的高效方案。通过机器视觉技术,结合实战项目经验,提供完整的代码解析和优化技巧,帮助开发者快速构建鲁棒性强、准确率高的检测系统,适用于电子制造和汽车线束等行业。

weixin_29098367的博客 441

最长公共子序列和最长公共子串(C语言实现)

核心思想: 利用动态规划的思想,通过设置一个临时数组t[][],其中t[i][j]表示,以Str1[i]作为末尾和以Str[2]作为末尾的最长公共子序列或者子串的长度。 算法步骤: (1)将输入的两个字符串分别存在数组a[]和b[]中,同时设置两个临时数组t1[][]和t2[][],第一个t1[i][j]表示a[]数组前i-1个字符串和b[]数组前j-1个字符串的最大公共子序列;第二个t2[i][j]表示a[]数组前i-1个字符串和b[]数组前j-1个字符串的最大公共子串; (2)循坏遍历两个字符串的所有字

qq_42453280的博客 9868

金属表面粗糙度对信号的影响

之前的文章中,已经采用CST中的微带线模块进行了很多的仿真分析,本文将再次利用这些模块,从另外一个角度去探讨关于传输线的使用问题--金属的表面粗糙度。 众所周知,数据传输中,当速率越来越高时,信号在金属介质中的趋肤效应就愈发明显,能量就会更多地集中于金属的表面进行流动,此时,如果金属表面不再光滑而是凹凸不平,能量的传输过程就会产生波动,当这种波动积累到一定的量级,就会严重影响到传输线的阻抗稳定性,从而导致信号失真和传输异常。

一只豌豆象的博客 2895

华为OD机试双机位C卷-字符串解密(Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【字符串解密】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 字符串解密。

qq_45776114的博客 734

最长公共子序列和最长公共子串——C++

一、给定两个字符串S1和S2,求两个字符串的最长公共子序列的长度。 输入样例 ABCD AEBD 输出样例 3 解释 S1和S2的最长公共子序列为ABD,长度为3 思路 动态规划 LCS(m,n)表示S1[0…m]和S2[0…n]的最长公共子序列的长度 S1[m] == S2[n]: LCS(m, n) = 1 + LCS(m - 1, n - 1); S1[m] != S2[n]: LCS(m, n) = max(LCS(m - 1, n), LCS(m, n - 1))。 #inc

qq_38236355的博客 1345

从通用到定制:营销Agent如何跨越数据鸿沟,实现对话SOP的个性化飞跃

从通用到定制:营销Agent如何跨越数据鸿沟,实现对话SOP的个性化飞跃

丨汀、的博客 656

最长公共子串和最长公共子序列

二者含义没搞清楚,雅虎的笔试就这样的写错了。 求最长公共字串的题目写成了最长公共子序列。 子串要求字符必须是连续的,但是子序列就不是这样了。悲催了。 子序列跟子串的求法类似,都是使用动态规划的思想,s1每次增加一个字符,看与s2当前位置的字符是不是相同,如果相同做相应的处理,如果不同,做另外的处理。 子序列的处理方式: 相同的情况下,该二维数组的位置等于[i-1][j-1]+1 不同的

imzoer的专栏 7813

PHM 2010数据集解读

PHM数据挑战赛是一项面向所有潜在与会者的竞赛。今年的挑战集中在使用测力仪、加速度计和声发射数据估计高速数控铣床刀具的RUL上。 博客对PHM 2010数据集的组成和信号进行了可视化。

cnjs1994的博客 7648

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

最长公共子序列和最长公共子串

最长公共子序列和最长公共子串 最长公共子序列: 最长公共子串: 最长公共子序列: 给定一个序列X=<x1,x2,x3,x4...,xm>,另一个序列Z=<z1,z2,z3,z4...,zk>,若存在一个严格递增的X的下标序列<i1,i2,i3,...,ik>对所有的1,2,3,...,k,都满足x(ik)=zk,则称Z是X的子序列 比如Z=<B,C,D,B>是X=<A,B,C...

weixin_42078660的博客 744

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

动态规划---求最长公共子序列和最长公共子串(C语言)

参考:https://blog.youkuaiyun.com/someone_and_anyone/article/details/81044153 一、求最长公共子序列 1、问题描述: 从一个给定的串中删去(不一定连续地删去)0个或0个以上的字符,剩下地字符按原来顺序组成的串。例如:“ ”,“a”,“xb”,“aaa”,“bbb”,“xabb”,“xaaabbb”都是串“xaaabbb”的子序列。(例子中的...

优快云 1万+

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

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

最长公共子序列(LCS)问题的解决及优化、最长公共子串问题

介绍了LCS问题的动态规划思想,并通过将其转化为LIS问题将时间复杂度优化到对数级;同时介绍了其简化问题最长公共子串的解法。

yuhaomogui的博客 5178

Python最长公共子串和最长公共子序列的实现

最长公共子串 (The Longest Common Substring)     LCS问题就是求两个字符串最长公共子串的问题。解法就是用一个矩阵来记录两个字符串中所有位置的两个字符之间的匹配情况,若是匹配则为1,否则为0。然后求出对角线最长的1序列,其对应的位置就是最长匹配子串的位置。#coding:utf-8 def find_lcs1(s1, s2): m=[[0 for i i

wateryouyo的博客 3万+

最长公共子序列和最长公共子串区别

最长公共子序列和最长公共子串区别        最长公共子串(Longest Common Substring)与最长公共子序列(Longest Common Subsequence)的区别: 子串要求在原字符串中是连续的,而子序列则只需保持相对顺序一致,并不要求连续。例如X = {a, Q, 1, 1}; Y = {a, 1, 1, d, f}那么,{a, 1, 1}是X和Y的最长公共子序列,但

qq_37171273的博客 1012
上一篇: 数组和为K的组合
下一篇: 01背包问题(动态规划DP)
MusicDancing
博客等级 码龄7年 2684粉丝 314原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值