当前位置:网站首页>动态规划_双数组字符串
动态规划_双数组字符串
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 :80750-24-9(脱硫生物素 NHS 酯)
If it is test axi dma catch a few words here
基于HDF的LED驱动程序开发(2)
使用 Allatori 进行 Jar 包混淆
长时间序列遥感数据处理及在全球变化、物候提取、植被变绿与固碳分析、生物量估算与趋势分析等领域中的应用
Finished product upgrade program
How to carry out AI business diagnosis and quickly identify growth points for cost reduction and efficiency improvement?
致-.-- -..- -
win10 uwp 使用 ScaleTransform 放大某个元素
对比几类主流的跨端技术方案
seata源码解析:seata server各种消息处理流程
格密码入门
"WAIC 2022 · hackers marathon" two ants wealth competition invited you to fight!
vehemently condemn
Force KouTi (5), the longest text string back
[Awards for Essays] Autumn recruitment special training to create your exclusive product experience
QT(41)-多线程-QTThread-同步QSemaphore-互斥QMutex
Initialization process of SAP UI5









