18int64_t lcs(
const std::string a,
const std::string b) {
19 int64_t m = a.length(), n = b.length();
20 std::vector<std::vector<int64_t>> res(m + 1, std::vector<int64_t>(n + 1));
21 std::vector<std::vector<int64_t>> trace(20, std::vector<int64_t>(20));
23 for (int64_t i = 0; i < m + 1; i++) {
24 for (int64_t j = 0; j < n + 1; j++) {
30 for (int64_t i = 0; i < m + 1; ++i) {
31 for (int64_t j = 0; j < n + 1; ++j) {
32 if (i == 0 || j == 0) {
37 else if (a[i - 1] == b[j - 1]) {
38 res[i][j] = 1 + res[i - 1][j - 1];
42 if (res[i - 1][j] > res[i][j - 1]) {
43 res[i][j] = res[i - 1][j];
46 res[i][j] = res[i][j - 1];