Language: C++

#include <bits/stdc++.h>
#define mk make_pair
using namespace std;

pair <int,int> prev[3005][3005];
int dp[3005][3005];

/*

axyb
abyxb 

*/

main()
{
	string a , b;
	cin >> a >> b;
	
	
	for(int i = 1;  i <= (int)a.size(); i++)
	{
		for(int j = 1; j <= (int)b.size(); j++)
		{
			if( a[i - 1] == b[j - 1] )
			{
				dp[i][j] = dp[i-1][j-1] + 1;
				prev[i][j] = mk(i-1 , j-1);
			}
			
			else if( dp[i-1][j] >= dp[i][j-1] )
			{
				dp[i][j] = dp[i-1][j];
				prev[i][j] = mk(i-1 , j);
			}
			else
			{
				dp[i][j] = dp[i][j-1];
				prev[i][j] = mk(i , j-1);
			}
		}
	}
	
	
	//for(int i = 1; i <= a.size(); i++)
	//{
		//for(int j = 1; j <= b.size(); j++)
		//{
			////cout << "(" << prev[i][j].first << " " << prev[i][j].second << " " << dp[i][j] << ")";
			//cout << dp[i][j] << ' ';
		//}
		//cout << endl;
	//}
	
	
	
	
	string ans = "";
	
	int i = a.size() , j = b.size();

	
	while( 1 )
	{
		if (!dp[i][j]) break;
		//cout << i << ' ' << j << ' ' << dp[i][j] << endl;
		if( dp[i-1][j-1] == dp[i][j] - 1 )
		{
			ans = a[i - 1] + ans;
			i--;
			j--;
			continue;
		}
		int I = i , J = j;
		
		i = prev[I][J].first;
		j = prev[I][J].second;
	}
		
	
	cout << ans << endl;
}


Compiler output:
a.cc:15:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:28:33: error: reference to 'prev' is ambiguous
   28 |                                 prev[i][j] = mk(i-1 , j-1);
      |                                 ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:5:16: note:                 'std::pair<int, int> prev [3005][3005]'
    5 | pair <int,int> prev[3005][3005];
      |                ^~~~
a.cc:34:33: error: reference to 'prev' is ambiguous
   34 |                                 prev[i][j] = mk(i-1 , j);
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:5:16: note:                 'std::pair<int, int> prev [3005][3005]'
    5 | pair <int,int> prev[3005][3005];
      |                ^~~~
a.cc:39:33: error: reference to 'prev' is ambiguous
   39 |                                 prev[i][j] = mk(i , j-1);
      |                                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:5:16: note:                 'std::pair<int, int> prev [3005][3005]'
    5 | pair <int,int> prev[3005][3005];
      |                ^~~~
a.cc:76:21: error: reference to 'prev' is ambiguous
   76 |                 i = prev[I][J].first;
      |                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:5:16: note:                 'std::pair<int, int> prev [3005][3005]'
    5 | pair <int,int> prev[3005][3005];
      |                ^~~~
a.cc:77:21: error: reference to 'prev' is ambiguous
   77 |                 j = prev[I][J].second;
      |                     ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:5:16: note:                 'std::pair<int, int> prev [3005][3005]'
    5 | pair <int,int> prev[3005][3005];
      |                ^~~~