Language: C++

#include <iostream>
using namespace std;
string s1,s2;
int prev[3001][3001];
int dp[3001][3001];
void backtrack(int,int);
bool succeed = false;
int main()
{
    ios::sync_with_stdio(false);
    cin>>s1>>s2;
    int n1 = s1.length();
    int n2 = s2.length();
    for(int i = 0; i < n1; i++)
    {
        for(int j = 0; j < n2; j++)
        {
            if(s1[i]==s2[j])
            {
                if(i==0||j==0)dp[i][j] = 1;
                else dp[i][j] = dp[i-1][j-1]+1;
                prev[i][j] = 0;
            }
            else
            {
                if(dp[i][j-1]>dp[i-1][j])
                {
                    dp[i][j] = dp[i][j-1];
                    prev[i][j] = 2;

                }
                else
                {
                    dp[i][j] = dp[i-1][j];
                    prev[i][j] = 1;
                }
            }
        }
    }
    backtrack(n1-1,n2-1);
    if(succeed)cout <<"\n";
}
void backtrack(int x,int y)
{
    if(x==-1||y==-1)return;
    if(prev[x][y]==0)
    {
        backtrack(x-1,y-1);
        succeed = true;
        cout << s1[x];
    }
    else if(prev[x][y] == 1)backtrack(x-1,y);
    else backtrack(x,y-1);
}


Compiler output:
a.cc: In function 'int main()':
a.cc:22:17: error: reference to 'prev' is ambiguous
   22 |                 prev[i][j] = 0;
      |                 ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:4:5: note:                 'int prev [3001][3001]'
    4 | int prev[3001][3001];
      |     ^~~~
a.cc:29:21: error: reference to 'prev' is ambiguous
   29 |                     prev[i][j] = 2;
      |                     ^~~~
/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:4:5: note:                 'int prev [3001][3001]'
    4 | int prev[3001][3001];
      |     ^~~~
a.cc:35:21: error: reference to 'prev' is ambiguous
   35 |                     prev[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:4:5: note:                 'int prev [3001][3001]'
    4 | int prev[3001][3001];
      |     ^~~~
a.cc: In function 'void backtrack(int, int)':
a.cc:46:8: error: reference to 'prev' is ambiguous
   46 |     if(prev[x][y]==0)
      |        ^~~~
/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:4:5: note:                 'int prev [3001][3001]'
    4 | int prev[3001][3001];
      |     ^~~~
a.cc:52:13: error: reference to 'prev' is ambiguous
   52 |     else if(prev[x][y] == 1)backtrack(x-1,y);
      |             ^~~~
/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:4:5: note:                 'int prev [3001][3001]'
    4 | int prev[3001][3001];
      |     ^~~~