当前位置:网站首页>[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;
}边栏推荐
- DenseNet网络论文学习笔记
- How to determine the progress bar loaded in the loading interface when opening the game
- Use ipmitool to configure BMC network and user information of X86 server
- Introduction to kubernetes resource objects and common commands (II)
- Poj-3486-computers[dynamic planning]
- RestCloud ETL实践之无标识位实现增量数据同步
- 【EXSI】主机间传输文件
- UE4渲染管线学习笔记
- RestCloud ETL WebService数据同步到本地
- 鼠标悬停效果七
猜你喜欢

【小程序项目开发-- 京东商城】uni-app之分类导航区域

Pychar open remote directory remote host

Share Creators萌芽人才培养计划来了!

How to use Jieba participle in unity

Detailed explanation of pointer array and array pointer (comprehensive knowledge points)

Huawei operator level router configuration example | BGP VPLS and LDP VPLS interworking example

PHP batch Excel to word

AI edge computing platform - beaglebone AI 64 introduction

Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and

Xception学习笔记
随机推荐
调试定位导航遇到的问题总结
PCB defect detection based on OpenCV and image subtraction
Record a service deployment failure troubleshooting
Is it safe to open an account online in a small securities firm? Will my money be unsafe?
基于OPENCV和图像减法的PCB缺陷检测
Scale SVG to container without mask / crop
Résumé des styles de développement d'applets Wechat
AI edge computing platform - beaglebone AI 64 introduction
Sampling Area Lights
Mouse over effect VI
【小程序项目开发-- 京东商城】uni-app之首页商品楼层
How to open a stock account? Also, is it safe to open an account online?
The operation efficiency of the park is improved, and the application platform management of applet container technology is accelerated
【小程序项目开发-- 京东商城】uni-app之分类导航区域
Poj-3486-computers[dynamic planning]
Mouse over effect III
Mnasnet learning notes
import tensorflow. contrib. Slim as slim error
Mouse over effect 10
Share Creators萌芽人才培養計劃來了!