当前位置:网站首页>[linear DP] longest common subsequence
[linear DP] longest common subsequence
2022-07-01 02:55:00 【Nathan Qian】
subject

897. Longest common subsequence - AcWing Question bank
AcWing 897. Longest common subsequence - AcWing
explain
- When a[i]==b[j] Update when
- f[i][j]=f[i-1][j-1]+1
- When a[i]!=b[j] When
- One of the letters must be discarded and not considered in the subsequence
- That is, the state transition is
- f(i,j)=max(f(i,j-1),f(i-1,j))
Code segment
#include<iostream>
using namespace std;
int n,m;
const int N=1010;
char a[N],b[N];
int f[N][N];
int main()
{
cin>>n>>m;
cin>>a+1>>b+1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(a[i]==b[j])f[i][j]=f[i-1][j-1]+1;
else
{
f[i][j]=max(f[i-1][j],f[i][j-1]);
}
}
cout<<f[n][m]<<endl;
}边栏推荐
- [applet project development -- JD mall] uni app commodity classification page (Part 2)
- [PR # 5 A] two way running (state pressure DP)
- Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?
- Share Creators萌芽人才培養計劃來了!
- Youmeng (a good helper for real-time monitoring of software exceptions: crash) access tutorial (the easiest tutorial for Xiaobai with some foundation)
- import tensorflow. contrib. Slim as slim error
- Viewing JVM parameters
- 股票开户安全吗?上海股票开户步骤。
- Saving images of different depths in opencv
- PTA 1017
猜你喜欢
随机推荐
[applet project development -- Jingdong Mall] classified navigation area of uni app
Gartner研究:在中国,混合云的采用已成为主流趋势
lavaweb【初识后续问题的解决】
鼠标悬停效果八
ipmitool下载地址和编译安装时可能出现的问题
Detailed explanation of pointer array and array pointer (comprehensive knowledge points)
【机器学习】向量化计算 -- 机器学习路上必经路
Restcloud ETL WebService data synchronization to local
Mouse over effect VI
Is it safe to open a stock account? Shanghai stock account opening procedures.
Huawei operator level router configuration example | configuration static VPLS example
Xception学习笔记
【小程序项目开发-- 京东商城】uni-app之首页商品楼层
mybati sql 语句打印
鼠标悬停效果六
Add / delete / modify query summary insert/create/put/add/save/post, delete/drop/remove, update/modify/change, select/get/list/find
Mouse over effect III
MCU firmware packaging Script Software
Thread Detach
使用ipmitool配置X86服务器的BMC网络和用户信息








