最长递增子序列 51Nod 1134 最长递增子序列

51nod 1134 最长递增子序列 dp(经典) 1134 最长递增子序列 基准时间限制:1 秒空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2  第2 - N + 1行:每行1个数,对应序 阅读详情

基准时间限制:1 秒 空间限制:131072 KB 分值: 0  难度:基础题
 收藏
 关注
给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)
例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。
Input
第1行:1个数N,N为序列的长度(2 <= N <= 50000)
第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9)
Output
输出最长递增子序列的长度。
Input示例
8
5
1
6
8
2
4
5
10
Output示例
5

第一次用的是最原始的版本,但是提交后时间超限。。。

这个时间复杂度是O(n^2)

#include<bits/stdc++.h>
using namespace std;
const int MAXN=50005;
const int INF=0x3f3f3f3f;
int a[MAXN];
int dp[MAXN];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		int ans=0;
		for(int i=0;i<n;i++)
		{
			dp[i]=1;
			for(int j=0;j<i;j++)
				if(a[j]<=a[i])	dp[i]=max(dp[i],dp[j]+1);
			ans=max(ans,dp[i]);
		}
		printf("%d\n",ans);
	}
	return 0;
}

后来又看了白书,有优化的版本,比着抄了一遍

这个用的是 lower_bound(),只需要循环一次就好,时间复杂度是O(nlogn);

代码如下

#include<bits/stdc++.h>
using namespace std;
const int MAXN=50005;
const int INF=0x3f3f3f3f;
int a[MAXN];
int dp[MAXN];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)	scanf("%d",&a[i]);
		int ans=0;
		memset(dp,0x3f,sizeof(dp));
		fill(dp,dp+n,INF);		
		for(int i=0;i<n;i++)
		{
			*lower_bound(dp,dp+n,a[i])=a[i];
		}
		printf("%d\n",lower_bound(dp,dp+n,INF)-dp);
	}
	return 0;
}




IFIX往Mysql数据库同步数据方法 通过IFix数据库向Mysql数据库同步数据 阅读详情

相关推荐

CANoe实战:LIN Slave一致性测试全流程解析

本文详细解析了使用CANoe进行LIN Slave一致性测试的全流程,包括测试概述、环境搭建、模块集成、测试用例详解及报告分析。通过实际案例分享,帮助工程师掌握LIN 2.0/2.1/2.2、SAE J2602和ISO 17987等标准的自动化测试方法,提升汽车电子从节点的可靠性和兼容性验证效率。

weixin_42665725的博客 533

1134 最长递增子序列

1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2 <=

昨日明眸 551

MCGS 和 200SMART 时间同步

在实际应用中,PLC经常会因为断电原因,导致时间不准确。假设我们设置了一个投加泵,每天8-18点投加。屏幕上显示的时间和PLC内部的时间,很可能不一样。所以需要在触摸屏上读取PLC的时间,并且提供设置功能。

mmxxoo_xxmmp的博客 1521

最长递增子序列---nlogn的解法

题目描述: 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2 &lt;= N &lt;= 50000)  第2 - N + 1行:每行1个数,对应序列的元素(-10^9 &lt;= Sii &lt;= 10^9) Ou...

Krismile_的博客 2515

单片机欠压保护、欠压复位的用法及作用

一. 前言 使用编程环境 :KEIL mdk4 单片机 : NRF24LE1   二. 分析 查询各开发芯片的数据手册,一般在电源管理或者复位设置章节中。以下NRF24LE1为例: Power supply supervisor(电源监控): 电源主管在开机时对系统进行初始化,对即将发生的情况提供预警当电源电压过低而不能安全运行时,系统处于复位状态。 电源管理框图如下:   ...

城南花已开的博客 8401

R语言pls包实战:手把手教你用偏最小二乘(PLS)搞定高维数据回归(附完整代码与数据标准化避坑指南)

本文详细介绍了如何使用R语言的pls包进行偏最小二乘(PLS)回归分析,特别针对高维数据回归问题。通过完整的代码示例和数据标准化避坑指南,帮助读者掌握从数据预处理到模型优化的全流程,解决实际应用中的常见问题。

weixin_42662605的博客 351

寻找数组最大递增子序列

寻找最大递增子序列是比较常见的算法,实现方式也不尽相同,图形化呈现便于理解!

Ethan's Blog 1534

virtualbox虚拟机里面最顶部没有控制、设置和帮助等选项

无意中操作,导致virtualbox虚拟机里面最顶部没有控制,设置和帮助选项  virtualbox虚拟机窗口显示如下如: 如何设置,窗口显示如下图所示呢: virtualbox虚拟机窗口模式显示设置,切换可以通过如下图所示操作进行切换: PS:一定要是右边的Ctrl+C

WEL测试 8780

动态规划问题之最长递增子序列

问题描述: 给定一个长度为N的数组,找出一个最长的递增子序列(给出的算法中只要满足<=即可,不需要严格递增)(不一定连续,但是顺序不能乱)。例如A{5,6,7,1,2,8},则其最长的单调递增子序列为{5,6,7,8},长度为4。 解题思路: 使用来两个数组longest和pre,longgest表示对应以当前元素为结尾的递增之序列长度,pre数组表示满足以当前元素为结尾的递增子序列的前一个...

Dr-Yang的博客 1144

YOLOv11 模型改进:利用新型损失函数实现精度跃升(含代码全解析)

在目标检测领域,损失函数的选择直接决定模型的精度上限。某自动驾驶公司将 YOLOv11 原有损失替换为新型损失后,障碍物检测 mAP 提升 10%,夜间场景误检率降低 22%;某物流分拣项目中,采用新损失的 YOLOv11 模型对小包裹的识别准确率从 82% 升至 96%。如果你也在为模型精度瓶颈、样本不平衡问题困扰,这篇教程将带你掌握 YOLOv11 损失函数的进阶技巧,真正帮你在检测性能上实现突破。损失函数是模型训练的“指南针”,它定义了模型“学习的方向”。传统损失(如 BCE、Focal Loss)在

m0_71589036的博客 714

基于STM32+OneNet设计的物联网智慧路灯(100)

本次设计的智能路灯采用STM32芯片和OneNet物联网平台进行连接,开发出支持太阳能充电锂电池供电、GPS定位上传位置信息、手动/自动控制路灯开关、环境光照调节、红外传感器检测周围人员、空气质量监测等多项功能。同时,当路灯发生异常情况时,系统可以自动发送邮件或短信到指定邮箱或电话。

7728

B - 最长递增子序列

给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input第1行:1个数N,N为序列的长度(2 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 ii <= 10^9) Output输出最长递增子序列的长度。 Sample Input

让你一生残梦的博客 486

Windows11配置WSL2支持代理上网

说起来本来这个功能我也不需要的,只是最近突然有个需求就顺便研究了下,WSL2默认的网络方式是NAT,即WSL2的网卡本身是虚拟网卡,通过以太网或WIFI的地址转换来上互联网,我试了下是不能直接走代理的,最近比较忙没具体研究,但是我用另一种方式实现了,下面介绍给需要的人。注意:这个方法只能是WIndows11系统,WIndows10系统上的WSL2缺少了一项功能导致不可用。1、方法总体没什么难度,NAT方式暂时没研究透,后续有时间再研究2、WIndows10系统不支持mirrored,暂时需要另辟蹊径。

jiexijihe945的博客 9591

51nod 1134 最长递增子序列

题目链接:51nod 1134 最长递增子序列 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N = 50001; 6 int a[N]; 7 int b[N]; 8 ...

dhe56357的博客 82

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

51Nod-1134-最长递增子序列

51Nod-1134-最长递增子序列 1134 最长递增子序列 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的

只想默默的博客 360

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

51nod 1134 最长递增子序列(dp+二分)

1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。Input第1行:1个数N,N为序列的长度(2 &lt;= N &lt;= 50000) 第2 - N + 1行:每行...

BBHHTT的博客 303

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

51Nod_1134 最长递增子序列【基础DP】

51Nod_1134 最长递增子序列 http://www.51nod.com/Challenge/Problem.html#!#problemId=1134 题目 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子...

逐梦者 267

51nod 1134 最长递增子序列

1134 最长递增子序列 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 输入 第1行:1个数N,N为序列的长度(2 <= N <= 50000) 第2 - N + 1行:每行1个数,对应序列的元素(-10^9 <= S[i] <= 10^9) 输出 ...

jialileng的博客 221

51Nod 1134 最长递增子序列

最长递增子序列 Description   给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的)     例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input    第1行:1个数N,N为序列的长度(2   第2 - N + 1行:每行1个数

getAC 357

51Nod-1134 最长递增子序列

1134 最长递增子序列  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2 &lt;= N &lt;= 50000)...

Revenant_Di的博客 307

51nod1134 最长递增子序列

给出长度为N的数组,找出这个数组的最长递增子序列。(递增子序列是指,子序列的元素是递增的) 例如:5 1 6 8 2 4 5 10,最长递增子序列是1 2 4 5 10。 Input 第1行:1个数N,N为序列的长度(2<=N<=50000) 第2-N+1行:每行1个数,对应序列的元素(-10^9<=S[i]&...

diudunhai7121的博客 97
上一篇: 二分搜索 51Nod 1267 4个数和为0
下一篇: FZU - 2213 Common Tangents
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值