当前位置:网站首页>动态规划_双数组字符串
动态规划_双数组字符串
2022-08-04 20:09:00 【Coding~Man】
两个题型,求最长连续子串和最长子串。
定义dp[m+1][n+1],表示的是字符串m的前i个字符和字符串n的前j个字符最长子串。
状态转移方程:
当charAt(i-1)==charAt(j-1)时候,dp[i][j]=dp[i-1][j-1]+1;
当charAt(i-1)!=charAt(j-1)时候,dp[i][j] = Math.max(dp[i-1][j],dp[i][j-1]);
最后返回dp[m][n];
最长连续子串时候
定义dp[m+1][n+1],表示的是字符串m的前i个字符和字符串n的前j个字符最长连续子串。
状态转移方程:当charAt(i-1)==charAt(j-1)时候,dp[i][j]=dp[i-1][j-1]+1; max=Math.max(max,dp[i][j]);
返回max;
边栏推荐
- 【CAS:2306109-91-9 |胺-PEG4-脱硫生物素】价格
- Finished product upgrade program
- 小软件大作用 | 如何省时省力进行Gerber图层快速对比?
- idea源码无法下载
- Order of lds links
- How to manually download and install SAP Fiori tools - Extension Pack for Visual Studio Code
- uwp ScrollViewer content out of panel when set the long width
- 基于Nodejs的电商管理平台的设计和实现
- Initialization process of SAP UI5
- 【有奖征文】秋招特训,打造你的专属产品体验
猜你喜欢

构建Buildroot根文件系统(I.MX6ULL)
Force KouTi (5), the longest text string back

Tensorflow2 环境搭建

How to promote the implementation of rural revitalization

vscode离线安装插件方法

使用百度EasyDL实现森林火灾预警识别

Zero-knowledge proof notes - private transaction, pederson, interval proof, proof of ownership

WIN10系统如何开启终端

ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators

QT(42)-QT线程-线程调用槽函数
随机推荐
uwp ScrollViewer content out of panel when set the long width
SAP 电商云 Accelerator 和 Spartacus UI 的工作机制差异
刷题-洛谷-P1304 哥德巴赫猜想
v-model的使用
常用正则表达式[通俗易懂]
阿里的arthas使用,入门报错:Unable to attach to 32-bit process running under WOW64
奥拉时钟芯片生成配置文件脚本
【Web漏洞探索】跨站脚本漏洞
零知识证明——zkSNARK证明体系
mysql的存储过程介绍、创建、案例、删除、查看「建议收藏」
数据安全解决方案的发展
lds链接的 顺序问题
完善的交叉编译环境记录 peta 生成的shell 脚本
搭建MyCat2一主一从的MySQL读写分离
linkboy 5.0 正式发布,新增语音识别、图像识别
Apache服务器配置多个站点
Ant Group's time series database CeresDB is officially open source
hash和history路由的区别
刷题-洛谷-P1319 压缩技术
Tensorflow2 环境搭建