记录12
作者:
Soel
,
2023-08-29 16:11:22
,
所有人可见
,
阅读 108
using i64 = long long;
std::ostream& operator<<(std::ostream& o, std::vector<int>& a) {
for (auto& x : a) o << x << ' ';
return o;
}
class oper {
public:
int operator()(int x)const {
return x;
}
};
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<int> a(n+1), b(m+1);
std::string s1, s2;
std::cin >> s1 >> s2;
std::transform(s1.begin(), s1.end(), a.begin() + 1, oper());
std::transform(s2.begin(), s2.end(), b.begin() + 1, oper());
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(m + 1));
i64 cnt = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = std::max(dp[i][j - 1], dp[i - 1][j]);
if (a[i] == b[j]) {
dp[i][j] = std::max({ dp[i][j],dp[i-1][j-1]+1});
}
cnt = std::max(cnt, 1LL*dp[i][j]);
}
}
std::cout << cnt << '\n';
}
auto main() -> signed {
std::cin.tie(nullptr)->sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(2);
solve();
return 0;
}