AcWing 897. 最长公共子序列
原题链接
简单
作者:
YMYS
,
2024-12-21 22:15:16
,
所有人可见
,
阅读 10
/*
* @Author: YMYS
* @Date: 2024-02-25 21:38:22
* @LastEditTime: 2024-09-03 20:23:59
* @FilePath: \VScode-C&C++-Coding\Acwing\算法基础课\5.第五章\2.线性DP\4.最长公共子序列.cpp
* @URL:https://www.acwing.com/problem/content/899/
* @Description: 题解推荐:https://www.acwing.com/solution/content/8111/
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int n,m;
char a[N],b[N];
int f[N][N];
int main()
{
cin>>n>>m>>a+1>>b+1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
f[i][j] = max(f[i-1][j], f[i][j-1]);
if(a[i] == b[j]) f[i][j] = f[i-1][j-1] + 1;
}
}
cout<<f[n][m]<<endl;
return 0;
}