Language: C++

#include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define int long long int
#define mii map<int, int>
#define vi vector<int>
#define fi(i, a, n)             \
    for (int i = 0; i < n; i++) \
    {                           \
        cin >> a[i];            \
    }
#define fo(i, a, n)             \
    for (int i = 0; i < n; i++) \
    {                           \
        cout << a[i] << " ";    \
    }
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define mk(arr, n, type) type *arr = new type[n];
#define pw(b, p) pow(b, p) + 0.1
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define lbrk printf("\n")

using namespace std; //_S_A_R_T_H_A_k_//
/// JAI SHREE RAM!!! ;{'*' <_l_> '*' };
/// Saare jahan se acha hindustan humara .....
/// JAI HIND DOSTON //-__ -//
int lcs(string s1, string s2){
if(s1.length() == 0 or s2.length()==0){
    return 0;
}
if (s1[0] == s2[0])
{
    return 1+lcs(s1.substr(1),s2.substr(1));
}
else
{
   return max(lcs(s1,s2.substr(1)),lcs(s1.substr(1),s2));
}
}
int dp[100][100];
vector<char> v;
int lcsTopDown(string s1, string s2){
if(s1.length() == 0 or s2.length()==0){
    return 0;
}
if(dp[s1.size()][s2.size()] !=-1 ){
    return dp[s1.size()][s2.size()];
}
int ans =0;
if (s1[0] == s2[0])
{   // cout<<s1[0]<<"hi"<<endl;
     ans = 1+lcs(s1.substr(1),s2.substr(1));
}
else
{
   ans =  max(lcs(s1,s2.substr(1)),lcs(s1.substr(1),s2));
}
dp[s1.size()][s2.size()] = ans ;
return ans ;
}
void lcsBU(string s1,string s2){
    int dp[100][100] = {0};
    for (int  i = 1; i <= n; i++)
    {
        for (int  j = 1; j <= m; j++)
        {
           if(s1[i-1]==s2[j-1]){
               v.push_back(s1[i-1]);
               dp[i][j] = 1 + dp[i-1][j-1];
           }
           else
           {
               dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
           }
        }        
        }
    //    return dp[s1.size()][s2.size()];
    int i = n;
    int j = m;
    string res;
    while (i>0 and j>0)
    {
        if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else if (dp[i][j]==dp[i-1][j])
        {
            i--;
        }
        else{
         res = res + s1[i-1];   
         i--;
        j--;
        }

    }
     for(int i=res.size()-1;i>=0;i--){
         cout<<res[i];
     }
     cout<<endl;
    }
int32_t main()
{
    ios_base::sync_with_stdio(0);
    string s1, s2;
    cin>>s1>>s2;
  // cout<<lcs(s1,s2)<<endl;
 int n =s1.length();
 int m = s2.length();
   for (int  i = 0; i <= n; i++)
   {
       for (int  j = 0; j <= m; j++)
       {
           dp[i][j] = -1;
       }
    }
   //cout<<lcsTopDown(s1,s2)<<endl;
   lcsBU(s1,s2,n,m);
//    for (auto it: v)
//    { 
//        cout<<it;
//    }
//    cout<<endl;
   return 0;
}
// 1
// 6
// 50 3 10 7 40 50
// ans - 4

Compiler output:
a.cc: In function 'void lcsBU(std::string, std::string)':
a.cc:72:27: error: 'n' was not declared in this scope
   72 |     for (int  i = 1; i <= n; i++)
      |                           ^
a.cc:74:31: error: 'm' was not declared in this scope
   74 |         for (int  j = 1; j <= m; j++)
      |                               ^
a.cc:87:13: error: 'n' was not declared in this scope
   87 |     int i = n;
      |             ^
a.cc:88:13: error: 'm' was not declared in this scope
   88 |     int j = m;
      |             ^
a.cc: In function 'int32_t main()':
a.cc:127:9: error: too many arguments to function 'void lcsBU(std::string, std::string)'
  127 |    lcsBU(s1,s2,n,m);
      |    ~~~~~^~~~~~~~~~~
a.cc:70:6: note: declared here
   70 | void lcsBU(string s1,string s2){
      |      ^~~~~