Language: C++

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int m = s.size(), n = t.size();
    vector<vector<int>> dp(m + 1, vector<int> (n + 1, 0));
    vector<vector<pair<int, int> >> f(m+1, vector<pair<int, int> > (n + 1));
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (s[i - 1] == t[j - 1] && dp[i - 1][j - 1] + 1 > dp[i][j]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                f[i][j] = pair<int, int>(i - 1, j - 1);
            }
         if (dp[i - 1][j] > dp[i][j]) {
                dp[i][j] = dp[i - 1][j];
                f[i][j] = pair<int, int>(i - 1, j);
            }
            if (dp[i][j - 1] > dp[i][j]) {
                dp[i][j] = dp[i][j - 1];
                f[i][j] = pair<int, int>(i, j - 1);
            }
        }
    }
    string res = "";
    int i = n, j = m;
    while (i != 0 && j != 0) {
        auto t = f[i][j];
        int ti = t.first, tj = t.second;
        if (ti == i - 1 && tj == j - 1) {
            res.push_back(s[i - 1]);
        }
        i = ti;
        j = tj;
    }
    cout << res.reverse() << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:4:5: error: 'string' was not declared in this scope
    4 |     string s, t;
      |     ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | using namespace std;
a.cc:5:5: error: 'cin' was not declared in this scope
    5 |     cin >> s >> t;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:5:12: error: 's' was not declared in this scope
    5 |     cin >> s >> t;
      |            ^
a.cc:5:17: error: 't' was not declared in this scope
    5 |     cin >> s >> t;
      |                 ^
a.cc:7:5: error: 'vector' was not declared in this scope
    7 |     vector<vector<int>> dp(m + 1, vector<int> (n + 1, 0));
      |     ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | using namespace std;
a.cc:7:19: error: expected primary-expression before 'int'
    7 |     vector<vector<int>> dp(m + 1, vector<int> (n + 1, 0));
      |                   ^~~
a.cc:8:19: error: 'pair' was not declared in this scope
    8 |     vector<vector<pair<int, int> >> f(m+1, vector<pair<int, int> > (n + 1));
      |                   ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | using namespace std;
a.cc:8:24: error: expected primary-expression before 'int'
    8 |     vector<vector<pair<int, int> >> f(m+1, vector<pair<int, int> > (n + 1));
      |                        ^~~
a.cc:10:30: error: 'n' was not declared in this scope
   10 |         for (int j = 1; j <= n; ++j) {
      |                              ^
a.cc:11:41: error: 'dp' was not declared in this scope
   11 |             if (s[i - 1] == t[j - 1] && dp[i - 1][j - 1] + 1 > dp[i][j]) {
      |                                         ^~
a.cc:13:17: error: 'f' was not declared in this scope
   13 |                 f[i][j] = pair<int, int>(i - 1, j - 1);
      |                 ^
a.cc:13:32: error: expected primary-expression before 'int'
   13 |                 f[i][j] = pair<int, int>(i - 1, j - 1);
      |                                ^~~
a.cc:15:14: error: 'dp' was not declared in this scope
   15 |          if (dp[i - 1][j] > dp[i][j]) {
      |              ^~
a.cc:17:17: error: 'f' was not declared in this scope
   17 |                 f[i][j] = pair<int, int>(i - 1, j);
      |                 ^
a.cc:17:32: error: expected primary-expression before 'int'
   17 |                 f[i][j] = pair<int, int>(i - 1, j);
      |                                ^~~
a.cc:19:17: error: 'dp' was not declared in this scope
   19 |             if (dp[i][j - 1] > dp[i][j]) {
      |                 ^~
a.cc:21:17: error: 'f' was not declared in this scope
   21 |                 f[i][j] = pair<int, int>(i, j - 1);
      |                 ^
a.cc:21:32: error: expected primary-expression before 'int'
   21 |                 f[i][j] = pair<int, int>(i, j - 1);
      |                                ^~~
a.cc:25:11: error: expected ';' before 'res'
   25 |     string res = "";
      |           ^~~~
      |           ;
a.cc:26:13: error: 'n' was not declared in this scope
   26 |     int i = n, j = m;
      |             ^
a.cc:27:22: error: 'j' was not declared in this scope
   27 |     while (i != 0 && j != 0) {
      |                      ^
a.cc:28:18: error: 'f' was not declared in this scope
   28 |         auto t = f[i][j];
      |                  ^
a.cc:30:28: error: 'tj' was not declared in this scope; did you mean 'ti'?
   30 |         if (ti == i - 1 && tj == j - 1) {
      |                            ^~
      |                            ti
a.cc:31:13: error: 'res' was not declared in this scope
   31 |             res.push_back(s[i - 1]);
      |             ^~~
a.cc:34:13: error: 'tj' was not declared in this scope; did you mean 'ti'?
   34 |         j = tj;
      |             ^~
      |             ti
a.cc:36:5: error: 'cout' was not declared in this scope
   36 |     cout << res.reverse() << endl;
      |     ^~~~
a.cc:36:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:36:13: error: 'res' was not declared in this scope
   36 |     cout << res.reverse() << endl;
      |             ^~~
a.cc:36:30: error: 'endl' was not declared in this scope
   36 |     cout << res.reverse() << endl;
      |                              ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;