mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:48:48 +00:00
897. 最长公共子序列
https://www.acwing.com/problem/content/submission/code_detail/8872887/
This commit is contained in:
parent
94532334c7
commit
354dd753d1
20
AcWing/897/897.cpp
Normal file
20
AcWing/897/897.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user