Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
 

void solve(){
    int Q;
    cin >> Q;
    while(Q--){
        string S, T;
        cin >> S >> T;
        int s_len = S.size();
        int t_len = T.size();
        
        vector<vector<int>> dp(s_len+1, vector<int>(t_len+1, 0));
        
        int ans = 0;
        for(int i=0; i<s_len; i++){
            for(int j=0; j<t_len; j++){
                if(S[i]==T[j])
                    dp[i+1][j+1] = dp[i][j] + 1;
                else
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);

                ans = max(ans, dp[i+1][j+1]);
            }
        }
        cout << ans << endl;
        
    }
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}

C++: #include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fr first
#define se second

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

vector<vector<int>>dp(30,vector<int>(50010,0));

signed main(){
  int N;cin>>N;
  vector<int> ans;
  REP(i,0,N){
    string S,T;cin>>S>>T;
    int s_size=S.size(),t_size=T.size();
    vector<vector<int>> dp(t_size+2,vector<int>(s_size+2));
    REP(i,1,t_size+1)REP(j,1,s_size+1){
      if(S.at(j-1)==T.at(i-1)){
        dp[i][j]=max(dp[i-1][j-1]+1,dp[i-1][j]);
      }
      else{
        dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
      }
    }
    // debug(dp)
    ans.push_back(dp[t_size][s_size]);
  }
  each(a,ans){
    print(a)
  }

}

C++: #include<iostream>
#include<string>
#include<algorithm>

static const int N = 1000;
using namespace std;

int LCS(string X,string Y){
  int m,n;
  
  m = X.size();
  n = Y.size();
  
  int dp[N + 1][N + 1] = {0};
  
  X = ' ' + X;
  Y = ' ' + Y;

  for(int i = 1;i <= m;i++){
    for(int j = 1;j <= n;j++){
      if(X[i] == Y[j]){
	dp[i][j] = dp[i - 1][j - 1] + 1;
      }else{
	dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
      }
    }
  }
  
  /*for(int i = 0;i < ax;i++){
    for(int j = 0;j < ay;j++){
      cout << dp[i][j] << " ";
    }
    cout << '\n';
    }*/
  
  return dp[m][n];
}

int main(){
  int q;
  string X,Y;
  
  cin >> q;
  
  for(int i = 0;i < q;i++){
    cin >> X >> Y;
    //cout << X.size() << " " << Y.size() << '\n';
    cout << LCS(X,Y) << '\n';
  }
  
  return 0;
}

C++: #include <iostream>
#include <string>

int solve(std::string &x, std::string &y){
    int c[1001][1001] = {};
    int m = x.length();
    int n = y.length();

    //for(int i = 1; i <= m; ++i) c[i][0] = 0;                                                                                                                                                                                      
    //for(int i = 1; i <= n; ++i) c[0][i] = 0;                                                                                                                                                                                      
    int maxval = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i =  1; i <= m; ++i){
        for(int j = 1; j <= n; ++j){
            if(x[i] == y[j]){
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = std::max(c[i][j - 1], c[i - 1][j]);
            }
            maxval = std::max(maxval, c[i][j]);
        }
    }
    return maxval;
}

int main(){
    int q;
    std::cin >> q;
    for(int i = 0; i < q; ++i){
        std::string x;
        std::string y;
        std::cin >> x;
        std::cin >> y;
        int res = solve(x, y);
        std::cout << res << "\n";
    }
    return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
#define max(a,b) (a>b ? a : b)
#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 1000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int resolve(string S, string T){
  int s = (int)S.size(), t = (int)T.size();
  vector<vector<int>> dp(s+1, vector<int>(t+1, 0));

  for(int i=0; i<s; i++){
    for(int j=0; j<t; j++){
      if(S[i]==T[j]) dp[i+1][j+1] = dp[i][j]+1;
      else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
    }
  }
  return dp[s][t];
}

int main(){
  int N;
  cin >> N;
  rep(i,N){
    string S, T;
    cin >> S >> T;
    cout << resolve(S, T) << endl;
  }
}