Language: C++

int solve(string &s, string &t, int n, int m)
{
	if(n == 0 || m == 0)
	{
		return 0;
	}

	if(dp[n][m] != -1)
	{
		return dp[n][m];
	}

	int ans = 0;
	if(s[n-1] == t[m-1])
	{
		ans = solve(s, t, n-1, m-1)+1;
	}
	else
	{
		ans = max(solve(s, t, n-1, m), solve(s, t, n, m-1));
	}

	dp[n][m] = ans;

	return ans;
}


int main() 
{
	string s, t;
	cin>>s>>t;
	dp.clear();
	int n = s.length(), m = t.length();
	for(int i = 0;i<=n;i++)
	{
		dp.push_back(vector<int> (m+1, -1));
	}

	int l = solve(s, t, n, m);
	

	int i = n, j = m;
	char res[l+1];
	res[l] = '\0';
	l--;
	while(i > 0 && j > 0)
	{
		if(s[i-1] == t[j-1])
		{
			res[l--] = s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1])
			i--;
		else
			j--;
	}

	cout<<res<<endl;
}

Compiler output:
a.cc:1:11: error: 'string' was not declared in this scope
    1 | int solve(string &s, string &t, int n, int m)
      |           ^~~~~~
a.cc:1:19: error: 's' was not declared in this scope
    1 | int solve(string &s, string &t, int n, int m)
      |                   ^
a.cc:1:22: error: 'string' was not declared in this scope
    1 | int solve(string &s, string &t, int n, int m)
      |                      ^~~~~~
a.cc:1:30: error: 't' was not declared in this scope
    1 | int solve(string &s, string &t, int n, int m)
      |                              ^
a.cc:1:33: error: expected primary-expression before 'int'
    1 | int solve(string &s, string &t, int n, int m)
      |                                 ^~~
a.cc:1:40: error: expected primary-expression before 'int'
    1 | int solve(string &s, string &t, int n, int m)
      |                                        ^~~
a.cc:1:45: error: expression list treated as compound expression in initializer [-fpermissive]
    1 | int solve(string &s, string &t, int n, int m)
      |                                             ^
a.cc: In function 'int main()':
a.cc:31:9: error: 'string' was not declared in this scope
   31 |         string s, t;
      |         ^~~~~~
a.cc:32:9: error: 'cin' was not declared in this scope
   32 |         cin>>s>>t;
      |         ^~~
a.cc:32:14: error: 's' was not declared in this scope
   32 |         cin>>s>>t;
      |              ^
a.cc:32:17: error: 't' was not declared in this scope
   32 |         cin>>s>>t;
      |                 ^
a.cc:33:9: error: 'dp' was not declared in this scope
   33 |         dp.clear();
      |         ^~
a.cc:37:30: error: 'vector' was not declared in this scope
   37 |                 dp.push_back(vector<int> (m+1, -1));
      |                              ^~~~~~
a.cc:37:37: error: expected primary-expression before 'int'
   37 |                 dp.push_back(vector<int> (m+1, -1));
      |                                     ^~~
a.cc:40:32: error: 'm' was not declared in this scope
   40 |         int l = solve(s, t, n, m);
      |                                ^
a.cc:40:33: error: 'solve' cannot be used as a function
   40 |         int l = solve(s, t, n, m);
      |                                 ^
a.cc:61:9: error: 'cout' was not declared in this scope
   61 |         cout<<res<<endl;
      |         ^~~~
a.cc:61:20: error: 'endl' was not declared in this scope
   61 |         cout<<res<<endl;
      |                    ^~~~