0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

897. 最长公共子序列

https://www.acwing.com/problem/content/submission/code_detail/8872887/
This commit is contained in:
Baoshuo Ren 2021-11-16 20:31:09 +08:00 committed by Baoshuo Ren
parent 94532334c7
commit 354dd753d1
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

20
AcWing/897/897.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, f[1005][1005];
string a, b;
int main() {
cin >> n >> m >> a >> b;
a = ' ' + a;
b = ' ' + b;
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] = max(f[i][j], f[i - 1][j - 1] + 1);
}
}
cout << f[n][m] << endl;
return 0;
}