Greatest Common Increasing Subsequence hdu1423 最长公共递增子序列

基于STM32、HAL库的ICP-20100气压传感器 驱动程序设计 它具有低功耗、高精度、快速响应等特点,非常适合物联网、可穿戴设备和无人机等应用。#define ICP20100_FIFO_CTRL 0x09 // FIFO控制寄存器。#define ICP20100_FIFO_DATA 0x0A // FIFO数据寄存器。#define ICP20100_FIFO_STS 0x0B // FIFO状态寄存器。#define ICP20100_FIFO_WTM 0x15 // FIFO水印设置。 阅读详情

http://acm.hdu.edu.cn/showproblem.php?pid=1423

下面是从前辈那里copy来的最长公共递增子序列的详解。

给出两个序列a和b,求序列的最长公共递增子序列
例如 a:1,4,2,5,-12   b:-12,1,2,4,最长的公共递增子序列是2(序列为2,4)。


解决方案:
用一个二维数组f[i][j]表示a序列的前i项,b序列的前j项,并且以b[j]结束的LCIS的长度。
则有:
当a[i] != b[j]时,f[i][j]=f[i-1][j]; //如果最后一项不等,那么f[i][j]必定与f[i-1][j]或者f[i][j-1]相等。
当a[i] == b[j]时,f[i][j]=max(f[i-1][k])+1,1<=k<=j-1 && b[j]>b[k];  //求f[i-1]行中的最长,并且保证新增的数大于已经有的数
但是这样的效率为O(n^3)。 不难发现,求f[i-1][k]的时候可以通过一个变量temp来解决,当k从1遍历到j的同时,可以不断更新temp的值,如果a[i]>b[j]时,令temp=max(temp,f[i-1][j]);如果a[i]==b[j]时,令f[i][j]=max+1。

#define N 1010
int a[N],b[N];
int f[N][N];

int LCIS(int a[],int b[],int lena,int lenb)
{
 int i,j,temp;
 memset(f,0,sizeof(f));
 for(i=1;i<=lena;i++)
 {
  for(j=1,temp=0;j<=lenb;j++)
  {
   f[i][j]=f[i-1][j];
   if(a[i]>b[j] && f[i-1][j]>temp)
    temp=f[i-1][j];
   if(a[i] == b[j])
    f[i][j]=temp+1;
  }
 }
 temp=0;
 for(i=1;i<=lenb;i++)
  if(f[lena][i] > temp)
   temp=f[lena][i];
 return temp;
}
f数组也可以改成一维数组,减少空间。f[i]表示原来的f[i][j],f[i]的值可以沿用上一次循环的值,所以原来代码中的f[i][j]=f[i-1][j]可以省略。

int f[N];
int LCIS(int a[],int b[],int lena,int lenb)
{
 int i,j,temp;
 for(i=1;i<=lena;i++)
 {
  for(j=1,temp=0;j<=lenb;j++)
  {
   if(a[i]>b[j] && f[j]>temp)
    temp=f[j];
   if(a[i]==b[j])
    f[j]=temp+1;
  }
 }
 temp=0;
 for(i=1;i<=lenb;i++)
  if(f[i]>temp)
   temp=f[i];
 return temp;
}

1432是一道单纯套公式的题目,但是题目没有给的描述是首先输入一个数表示测试用例的数量,然后每组测试用例之间有一行空行。

#include <iostream>
using namespace std;
#define NLEN 505
int a[NLEN],b[NLEN],f[NLEN][NLEN];

int main(){
#ifndef ONLINE_JUDGE
	freopen("1423in.txt","r",stdin);
#endif
	int t,n,m,i,j,temp,ce=0;
	scanf("%d",&t);
	while (t--){
		ce++;
		scanf("%d",&n);
		for (i=1;i<=n;i++)
			scanf("%d",&a[i]);
		scanf("%d",&m);
		for (i=1;i<=m;i++)
			scanf("%d",&b[i]);
		for (i=0;i<=n;i++)
			f[i][0]=0;
		for (j=0;j<=m;j++)
			f[0][j]=0;
		for (i=1;i<=n;i++)
			for (j=1,temp=0;j<=m;j++){
				f[i][j]=f[i-1][j];
				if (a[i]>b[j]&&f[i-1][j]>temp)//更新Temp
					temp=f[i-1][j];
				if (a[i]==b[j])
					f[i][j]=temp+1;
			}
		for (j=0;j<=m;j++)
			if (f[n][j]>temp)
				temp=f[n][j];
		if (ce!=1)
			putchar(10);
		printf("%d\n",temp);
	}
	return 0;
}



C# WPS操作PPT,全屏,缩率图,备注,跳转播放 本文介绍了一个使用C#开发的PPT操作工具,主要功能包括检测当前打开的PPT文件、获取选中PPT路径、指定播放PPT、获取PPT页面序号和缩略图、提取备注内容等。文章展示了操作界面效果图,并重点解决了用户手动退出PPT后重新获取路径时报错的问题。核心代码实现了通过WPS API进行PPT文件的打开、全屏播放、页面跳转、获取当前页位置等功能,同时支持生成PPT缩略图预览和备注信息提取。当用户未通过工具按钮打开PPT时,程序会自动初始化PPT信息确保功能正常使用。 阅读详情

相关推荐

高通CamX架构解析(一)——核心组件与数据流设计

本文深入解析高通CamX相机架构的核心组件与数据流设计。CamX采用模块化与数据驱动思想,将复杂处理流程拆解为Node、Pipeline、Session等独立组件,并通过CHI层实现硬件接口与定制功能的分离。文章详细阐述了从请求下发到结果返回的完整数据流,并提供了实用的调试与分析指南,帮助开发者理解这一高效、灵活的现代相机架构。

k8l9m0n的博客 237

hdu 1423最长公共递增子序列

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2881    Accepted Submission(s): 901 Problem Descripti

云华100的专栏 563

数字IC物理验证实战 | 从Calibre LVS报告到Innovus定位的Debug全链路解析

本文详细解析了数字IC物理验证中Calibre LVS报告的Debug全流程,从INCORRECT NETS错误的初探到Innovus定位技巧,提供了实战案例和高效工具的使用方法。重点介绍了Calibre高亮功能、Innovus验证命令以及前后端工具联动的关键策略,帮助工程师快速定位和解决LVS问题,提升物理验证效率。

weixin_30919429的博客 133

HDU 1423 子序列

Greatest Common Increasing Subsequence Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.   Input Each sequence is descr

u011566113的专栏 571

自适应陷波器的原理与实现

x(t)是叠加有两个频率干扰信号的输入信号,s(t)是需要保留的有用信号,在输入信号中,我们只知道频率w1和w2,但不知道信号的幅度A和相位θ,自适应陷波器可以估计两个未知的幅度和相位值,这需要我们提供两路相互正交的单频信号,如cos(w1t)、sin(w1t),通过调整其权值,从而合成出与干扰信号完全相同的信号A1cos(w1t+θ1),从而实现干扰信号的滤除。采用LMS算法,在保证不损失其他有用信号的情况下,有效地抑制输入信号中某一频率的干扰,如需滤除多个频率,只需要增加相应的输入信号。

Melkiades2333的博客 6911

RustDesk网页端远程控制实战:如何用Web Client替代传统客户端(附安全配置建议)

本文详细介绍了RustDesk网页端远程控制的实战应用,包括其核心优势、配置流程及安全加固方案。通过Web Client替代传统客户端,用户可实现跨平台无缝体验和企业级管理效率,特别适合临时协作和移动设备使用。文章还提供了JWT身份验证、LDAP集成等安全配置建议,确保网页端访问的安全性。

weixin_30836759的博客 266

hdu 1423(最长公共递增子序列)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1423 思路:dp[i][j]表示序列1(1-i)和序列2(1-j)最长的公共子序列 View Code 1 #include&lt;iostream&gt; 2 #include&lt;cstdio&gt; 3 #include&lt;cstring&gt; 4 #inclu...

weixin_33756418的博客 145

用Python+OpenCV搞定线激光相机标定:从棋盘格到3D点云的保姆级实战

本文详细介绍了使用Python和OpenCV进行线激光相机标定的全流程实战,从硬件准备到3D点云重建。涵盖相机内参标定、激光平面方程拟合、三维重建等关键技术,提供完整的代码实现和工程优化建议,帮助开发者实现毫米级精度的工业检测和三维测量系统。

weixin_29227425的博客 296

hdu1423 LCIS

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define sss(a,b,c) scanf("%d%d%d",&a,&b,

bigsungod的专栏 873

记录Rancher集群中coredns问题导致的服务DNS解析超时

coredns问题处理

1362

【Altium Designer】Off grid pin解决方法

​今天我画完原理图编译时,出现了太多的黄色(出现warning警告提示)Off grid pin警告,这个警告并不是原理图电气连接出问题了,而是元器件或器件PIN脚没有和栅格对齐造成的原因。再编译还是出现这个警告。 最后经过不断翻阅网上经验和实践,才最终解决,本经验详细记录了解决该警告的有效方法。 解决方案:以下是问题解决步骤... ​

夜半少年的博客 7555

hdu1423

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1353 Accepted Submission(s): 404 Problem Descripti

hechenghai 1047

数学建模学习(120):使用Python实现基于AHP的供应商选择分析

使用Python实现基于AHP的供应商选择分析

全栈川川 920

hdu1423Greatest Common Increasing Subsequence(最长公共递增子序列)

Greatest Common Increasing Subsequence Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 10   Accepted Submission(s) : 3 Problem Descripti

496

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列lcis)

http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. Input Each sequence ...

diansitao5461的博客 206

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

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

HDU1423 Greatest Common Increasing Subsequence(最长公共递增子序列)

This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. Input Each sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2

UncleJokerly 663

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

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列LICS)

Greatest Common Increasing Subsequence Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.   Input Each sequenc

小张的专栏 653

hdu 1423 Greatest Common Increasing Subsequence_LICS(最长公共递增子序列)

#include #include using namespace std; int dp[1005][1005]; int a[100010],b[100010]; int main() { int t,i,j,m,n; cin>>t; while(t--) { memset(a,0,sizeof(a)); memset(b,0

Diors 834

hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列

hdu 1423 Greatest Common Increasing Subsequence http://acm.hdu.edu.cn/showproblem.php?pid=1423 #include #include #include #include using namespace std; int ch1[1110], ch2[1110], dp[1110], len1,

倩 520

HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS)

HDU 1423 Greatest Common Increasing Subsequence(最长公共上升LCIS) http://acm.hdu.edu.cn/showproblem.php?pid=1423 题意:        给你两个数字组成的串a和b,要你求出它们的最长公共严格递增子序列的长度(LCIS). 分析:        首先我们令f[i][j]==x表示是a...

weixin_34221773的博客 97

HDU1423 Greatest Common Increasing Subsequence【最长公共子上升序列 +DP】

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 11284 Accepted Submission(s): 3638 Problem Descriptio...

海岛Blog 715

HDU 1423 Greatest Common Increasing Subsequence(单调递增公共子序列)

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6831    Accepted Submission(s): 2216 Problem De

光明~~~ 2万+

Greatest Common Increasing Subsequence HDU - 1423 (最大上升递增子序列)

Description This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. Input Each sequence is described with M - its length (1 <= M <= 500) and M in...

Jin_Yanhui 210

hdu 1423 Greatest Common Increasing Subsequence (最长上升子序列)

1、http://acm.hdu.edu.cn/showproblem.php?pid=1423 参考百度文库http://wenku.baidu.com/view/3e78f223aaea998fcc220ea0.html 2、题目大意: 求两个字符串的最大上升子序列,LCIS解决即可 Greatest Common Increasing Subsequence Time Limit:

chx 602

HDU 1423--Greatest Common Increasing Subsequence【LCIS】

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4847    Accepted Submission(s): 1547 Problem Desc

_阿阿阿阿欢 573

hdu 1423 Greatest Common Increasing Subsequence

Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2847 Accepted Submission(s): 885 Problem Desc...

weixin_30297281的博客 77
上一篇: Max Sum hdu1003 最大子段和
下一篇: Smith Numbers hdu1333 素数
花酱_
博客等级 码龄14年 30粉丝 100原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值