lcs 最小实现(nlgn)

动态规划--最长递增子序列(LIS)-最长公共子序列(LCS) 动态规划--最长递增子序列(LIS)-最长公共子序列(LCS)LIS最长递增子序列,朴素的是o(n^2)算法,二分下可以写成o(nlgn):维护一个当前最优的递增序列——找到恰好大于它更新LCS最长公共子序列,通常o(n^2)的算法************************************************************************************... 阅读详情

 lcs可有三种实现 ,

1,n*n/2 ,

2 ,dp ,,排序后,寻找最长公共序列 nlogn+n*n

3 ,  dp  ,记录各个len所需的最小数字限额法 ,O(n*lgn)

/*
writen by widyrobin
windyrobin@hotmail.com
04/10/2008
*/


#include 
<iostream>
using namespace std;

#define  MAX_INPUT_NUM 10000
int limit[MAX_INPUT_NUM];

int main()
{
    
int inputNum;
    
int curNum;
    
int tempBegin;
    
int tempEnd;
    
int tempMiddle;
    
int len;
    
    
while(cin>>inputNum){
        len
=0;//the count
        for(int i=0;i<inputNum;i++){
            cin
>>curNum;

            tempEnd
=len;
            tempBegin
=1;
            tempMiddle
=0;

            
while(tempBegin<=tempEnd){
                tempMiddle
=(tempBegin+tempEnd)>>1;
                limit[tempMiddle] 
>=curNum ? tempEnd=tempMiddle-1 : tempBegin=tempMiddle+1;
            }

            limit[tempBegin]
=curNum;//first position whose value >=curNum ,if no existed ,is end+1
            tempBegin >len ? len++ :NULL;
    
        }
//end for ..
        cout<<len<<endl;
    }
//end while

    
return 0;
}

利用动态规划找出最长公共单调递增子序列 动态规划法求最长递增子序列的两种方法,一个是n²,一个是nlgn时间的。 阅读详情

相关推荐

步进电机 cia402协议 报文自己的理解 (笔记)

步进电机 cia402协议 报文自己的理解 (笔记)

she666666的博客 3827

nLogn LCS 算法总结

参考:http://www.cs.ucf.edu/courses/cap5937/fall2004/Longest%20common%20subsequence.pdf 最长公共子序列 的 nlogn 的算法本质是 将该问题转化成 最长增序列(LIS),因为 LIS 可以用nlogn实现,所以求LCS的时间复杂度降低为 nlogn。 1. 转化:将LCS问题转化成LIS问题。

1万+

C#构建企业级AI Agent框架:从架构到实践

AI Agent作为智能系统的核心组件,通过结合大语言模型(LLM)与规划引擎,实现了从简单对话到复杂任务处理的跨越。其关键技术包括记忆系统(RAG架构)和工具调用机制,前者通过向量数据库实现知识检索,后者则扩展了Agent的功能边界。在企业级应用中,这类系统能显著提升效率,如HR政策查询、IT故障排查等场景。C#凭借其强类型和高效性能,成为实现这类系统的理想选择,特别是在需要与现有企业系统集成的场景下。通过合理设计工具接口和安全防护措施,可以构建出既强大又可靠的智能助手。

weixin_33672109的博客 385

O(nlogn)LIS及LCS算法

morestep学长出题,考验我们,第二题裸题但是数据范围令人无奈,考试失利之后,刻意去学习了下优化的算法 一、O(nlogn)的LIS(最长上升子序列) 设当前已经求出的最长上升子序列长度为len。先判断A[t]与D[len]。若A [t] > D[len],则将A[t]接在D[len]后将得到一个更长的上升子序列,len = len + 1, D[le...

weixin_30703911的博客 352

手写Socket Web服务器:深入HTTP协议底层原理

HTTP协议是Web通信的基石,其本质是一套严格定义的文本格式与状态交互规范。理解它需回归传输层——TCP连接建立、请求响应格式(如状态行、头/体分隔符\r\n\r\n)、字符编码与字节长度一致性等核心原理。这些知识直接决定CORS拦截、中文乱码、Content-Length错误等高频问题的排查效率。在现代框架封装日益厚重的今天,亲手用Socket实现一个可被Chrome识别的极简Web服务器,成为掌握Web运行机制最有效的实践路径。本文即以DebugLZQ经典案例为蓝本,还原从URI解析、DNS查询、So

weixin_40192258的博客 539

单像素成像技术原理与Matlab仿真实现

傅里叶变换是数字图像处理的核心数学工具,它将图像从空间域转换到频率域表示。基于傅里叶频谱分析的成像技术通过采集关键频率分量实现图像重建,这种原理催生了单像素成像这一创新技术。单像素成像利用空间光调制器和单个探测器直接测量傅里叶系数,结合压缩感知算法实现高效成像,在红外、太赫兹等特殊波段展现出独特优势。通过Matlab仿真可以验证傅里叶基测量矩阵的构建、压缩感知重建等关键技术环节,为实际系统开发提供理论基础。该技术在弱光环境成像、显微观测等领域具有重要应用价值,其低成本特性也大大降低了特殊波段成像的门槛。

weixin_29061425的博客 353

LIS、LCS 的o(n^2) 和 o(nlogn)算法小结

目录 LIS(N^2) LIS(N logN) LCS(N^2) LCS(N logN) 因为学习LCS和LIS已经有一段时间了,当时的代码和文件都丢的差不多了,下面的模板和代码都是全新手打,难免有一些小错误。有时间再改进吧。 LIS —— O(N^2)算法,简单的取每个数和前面的数进行比对,例如加入6,和前面逐一比较,并取前面小于 6 的数的下标最大值,它的下标就代表了序列到6为止LIS的长度。

Nodies 3654

【第24例】华为 IPD 体系 | RMT 需求管理团队

RMT需求管理团队

产品线负责人 1790

最长递增子序列

问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4.   解法1:最长公共子序列法 这个问题可以转换为最长公共子序列问题。如例子中的数组A{5,6, 7, 1, 2, 8},则我们排序该数组得到数组A‘{1, 2, 5, 6, 7

__七把刀__ 1万+

黑猫带你学eMMC协议第2篇:eMMC部分相关名词释义

1 前言 1.1 声明 本文依据eMMC JEDEC5.1、网络资料及个人工作经验整理而成,如有错误请留言。 本文结合eMMC JEDEC5.1协议手册查看效果更佳。 1.2 本文背景 本文关键词不包括emmc jedec5.1协议第3章节:《Terms and definitions》内容。关于emmc协议层的关键词,直接查阅spec相关章节即可,清晰明了,此处没必要再列出。 本文为本人工作学习中常听到或常用到关乎于emmc/flash的一些关键词合集,没有固定分类,不需要强行记忆,供查询使用。 1.

黑猫奥利奥的博客 7484

具身智能:原理、算法与系统 第3章 具身智能的感知-认知-行为框架

具身智能的PCB框架源于对生物智能系统的观察:动物通过感官接收环境信息(感知),基于内部模型进行预测和决策(认知),并通过身体执行动作改变环境(行为),而这一改变又通过感知反馈形成闭环。这一框架在两篇核心文献中得到了深入阐述:提出了系统的数学形式化和工程实现,则从认知科学角度强调了归纳偏置和双过程理论的重要性。

VectorShift的博客 164

编号(长度)为状态的动态规划(LCS,LIS等)

这一系列的文章是一步步的按照Amber大牛的DP总结一步步的写各个分类的DP的记录。之后做DP会更新增加这一系列的文章的内容的。 共性总结  本类的状态是基础的基础,大部分的动态规划都要用到它,成为一个维。  一般来说,有两种编号的状态:  状态(i)表示前i个元素决策组成的一个状态。  状态(i)表示用到了第i个元素,和其他在1到i-1间的元素,决策组成有的一个状态。

silentsky的专栏 478

40.8K星爆火!Crawl4AI实战突破Cloudflare 5秒盾:AI反爬新范式,爬虫再也不被封

Crawl4AI的爆火(40.8K星)不是偶然——它解决了爬虫工程师最头疼的反爬问题,让爬虫从“体力活”变成“脑力活”,不用再花费大量时间配置指纹、编写行为脚本。但要注意:爬虫必须遵守目标网站的robots.txt协议,不得用于非法爬取数据(比如用户隐私、商业机密)。合理使用技术,才能长久落地。如果你在使用Crawl4AI时遇到具体问题(比如绕过更严格的反爬、批量爬取配置),欢迎在评论区交流,我会第一时间分享解决方案!

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1609

最长递增子序列的三种算法

转载自:http://qiemengdao.iteye.com/blog/1660229 最长递增子序列   问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4.   解法1:最长公共子序列法 这个问题可以转换为最长公共子序...

小灰狼与大白兔的博客 3万+

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

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

(转)最长递增子序列的三种算法

转载自:http://qiemengdao.iteye.com/blog/1660229 最长递增子序列   问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4.   解法1:最长公共子序列法 这个问题可以转换为最长公共子序...

Gamer_Lee的博客 300

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【转载】最长递增子序列

转载自:http://qiemengdao.iteye.com/blog/1660229 最长递增子序列   问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为...

qq_39492842的博客 310

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

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

数据结构基础 之 最长递增子序列

问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4.   解法1:最长公共子序列法 这个问题可以转换为最长公共子序列问题。如例子中的数组A{5,6, 7, 1, 2, 8},则我们排序该数组得到数组A‘{1,

稚枭天卓 954

最长递增子序列O(nlogn)和O(n2)

单调子序列包含有单调递增子序列和递减子序列,不失一般性,这里只讨论单调递增子序列。首先,从定义上明确我们的问题。给定序列a1, a2, …, an,如果存在满足下列条件的子序列 ai1i2im, (其中i1 即称为一个原序列的长度为m的单调递增子序列,那么,现在的问题是我们要找出一个序列的最长的单调递增子序列。   直观上来说,一个序列Sn,它有2n个子序列,枚举所有的

fly around 2697
poboy
博客等级 码龄21年 1粉丝 1原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值