Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

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;
  }
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#define MAX_N 1000

int solve(std::string s,std::string t){
        int dp[MAX_N][MAX_N]={0};
        int n,m;
        n=s.size(),m=t.size();
        for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                        if(s[i]==t[j])
                                dp[i+1][j+1]=dp[i][j]+1;
                        else
                                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
        }
        return dp[n][m];
}

int main(){
        int q;
        std::cin>>q;
        for(int i=0;i<q;i++){
                std::string s,t;
                std::cin >> s>>t;
                std::cout<<solve(s,t)<<std::endl;
        }
        return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i < n; ++i)
#define max(a, b) a > b ? a : b

int main(void) {
  int n;
  scanf("%d", &n);
  rep(i, n) {
    char x[1500], y[1500], h, w;
    scanf("%s", x);
    scanf("%s", y);
    h = strlen(x), w = strlen(y);
    int dp[h][w], len[w];
    rep(j, h) rep(k, w) dp[j][k] = 0;
    rep(j, w) if(x[0] == y[j]) dp[0][j] = 1;
    len[0] = 0;
    repi(j, w) len[j] = dp[0][j - 1] | len[j - 1];
    repi(j, h) {
      rep(k, w) if(x[j] == y[k]) dp[j][k] = len[k] + 1;
      repi(k, w) len[k] = max(dp[j][k - 1], len[k - 1]);
    }
   /* rep(j, h) {
      rep(k, w) printf("%d ", dp[j][k]);
      printf("\n");
    }*/
    int max = 0;
    rep(j, w) if(max< dp[h - 1][j]) max = dp[h - 1][j];
    printf("%d\n", max);
  }
  return 0;
}