Language: C++

#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

int dp[3009][3009]{};
int main()
{

    string s,t; cin>>s>>t;

    int n = s.length() ;
    int m = t.length();

    for(int i = 0 ; i<n ; i++)
    {
        for(int j = 0 ; j<m ; j++)
        {
            if(s[i]==t[j])
            {
                int add = 0;
                if(i-1>=0 && j-1>=0 )add= dp[i-1][j-1];
                dp[i][j] = 1+ add;
            }
            else
            {
                int row = 0; int col=0;
                if(i-1>=0)row = dp[i-1][j];
                if(j-1>=0)col = dp[i][j-1];
                dp[i][j] = max(row ,col);
            }
        }
    }

    string LCS = "";
    int i = n-1; int j=m-1;
    while(i>=0 && j>=0)
    {
            if(i==0 && j==0 )
            {
                if(dp[0][0]>0)
                    LCS+=s[0];

                break;
            }

            int row = 0 ;  int col=0;
            if(i-1>=0)row = dp[i-1][j];
            if(j-1>=0)col = dp[i][j-1];
            if(dp[i][j]> row  && dp[i][j]> col)
            {
                LCS += s[i];
                i-=1;
                j-=1;
            }
            else if(dp[i][j]==row)
            {
                i--;
            }
            else if(dp[i][j]==col)
            {
                j--;
            }
    }


    reverse(LCS.begin() , LCS.end());
    cout<<LCS<<endl;
    return 0;
}
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

int dp[3009][3009]{};
int main()
{

    string s,t; cin>>s>>t;

    int n = s.length() ;
    int m = t.length();

    for(int i = 0 ; i<n ; i++)
    {
        for(int j = 0 ; j<m ; j++)
        {
            if(s[i]==t[j])
            {
                int add = 0;
                if(i-1>=0 && j-1>=0 )add= dp[i-1][j-1];
                dp[i][j] = 1+ add;
            }
            else
            {
                int row = 0; int col=0;
                if(i-1>=0)row = dp[i-1][j];
                if(j-1>=0)col = dp[i][j-1];
                dp[i][j] = max(row ,col);
            }
        }
    }

    string LCS = "";
    int i = n-1; int j=m-1;
    while(i>=0 && j>=0)
    {
            if(i==0 && j==0 )
            {
                if(dp[0][0]>0)
                    LCS+=s[0];

                break;
            }

            int row = 0 ;  int col=0;
            if(i-1>=0)row = dp[i-1][j];
            if(j-1>=0)col = dp[i][j-1];
            if(dp[i][j]> row  && dp[i][j]> col)
            {
                LCS += s[i];
                i-=1;
                j-=1;
            }
            else if(dp[i][j]==row)
            {
                i--;
            }
            else if(dp[i][j]==col)
            {
                j--;
            }
    }


    reverse(LCS.begin() , LCS.end());
    cout<<LCS<<endl;
    return 0;
}


Compiler output:
a.cc:78:5: error: redefinition of 'int dp [3009][3009]'
   78 | int dp[3009][3009]{};
      |     ^~
a.cc:7:5: note: 'int dp [3009][3009]' previously defined here
    7 | int dp[3009][3009]{};
      |     ^~
a.cc:79:5: error: redefinition of 'int main()'
   79 | int main()
      |     ^~~~
a.cc:8:5: note: 'int main()' previously defined here
    8 | int main()
      |     ^~~~