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 <iostream>
#include <algorithm>
#include <string>

using namespace std;

int c[1005][1005];

int lcs( string X, string Y){

    int m, n, i, j;

    m = X.size();
    n = Y.size();

    X = ' ' + X;
    Y = ' ' + Y;

    int Lmax = 0;

    for( i = 1; i <= m ; i++){

        c[i][0] = 0;

    }

    for( i = 1; i <= n ; i++ ){

        c[0][i] = 0;

    }

    for( i = 1; i <= m; i++ ){

        for( j = 1; j <= n ; j++ ){

            if( X[i] == Y[j] ){

                c[i][j] = c[i-1][j-1] + 1;

            } else if( c[i-1][j] >= c[i][j-1] ){

                c[i][j] = c[i-1][j];

            } else {

                c[i][j] = c[i][j-1];

            }

            Lmax = max( Lmax, c[i][j] );

        }

    }

    return Lmax;

}

int main(){

    int n;
    string X, Y;

    cin >> n;

    for( int i = 0 ; i < n ; i++ ){

        cin >> X >> Y;

        cout << lcs( X, Y) << endl;

    }

    return 0;

}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main(){
  int n;
  char x[1001],y[1001];
  int dp[1002][1002];
  
  //initialize
  for(int i=0;i<1002;i++){
    for(int j=0;j<1002;j++){
      dp[i][j]=0; 
    }
  }

  //load n;
  cin >>n;
  for(int i=0;i<n;i++){
    //load string
    scanf("%s",x);
    scanf("%s",y);
    //dp
    for(int j=0;j<strlen(x);j++){
      for(int k=0;k<strlen(y);k++){
	if(x[j]==y[k]){
	  dp[j+1][k+1]=dp[j][k]+1;
	}

	else{
	  if(dp[j][k+1]>dp[j+1][k]){
	    dp[j+1][k+1]=dp[j][k+1];
	  }

	  else{
	    dp[j+1][k+1]=dp[j+1][k];
	  }
	}
      }
    }

    //print
    cout <<dp[strlen(x)][strlen(y)]<<endl;
  }



  return 0;
}

C++: #include <iostream>

using namespace std;

int max_length(string x, string y)
{
    int n = x.size();
    int m = y.size();
    int dp[n+1][m+1];
    for(int i = 0; i <= m; ++i)
    {
        dp[0][i] = 0;
    }
    for(int i = 1; i <= n; ++i)
    {
        dp[i][0] = 0;
        for(int j = 1; j <= m; ++j)
        {
            if(x[i-1] == y[j-1])
            {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    return dp[n][m];
}

int main()
{
    string str1;
    string str2;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> str1 >> str2;
        cout << max_length(str1, str2) << endl;
    }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int lcs(string x, string y){
    int n = x.size();
    int m = y.size();
    int dp[n+1][m+1];
    for(int i = 0;i<n+1;i++)dp[i][0] = 0;
    for(int j = 0;j<m+1;j++)dp[0][j] = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(x[i]==y[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[n][m];
}

int main(){
    int n;cin>>n;
    // string s1,s2;
    for(int i=0;i<n;i++){
        string s1,s2;
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
    return 0;
}

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

int main(){
	int q;
	std::string a, b;
	std::vector< std::vector< int > > dp;
	
	dp.resize(1001);
	for(int i=0;i<=1000;++i){
		dp[i].resize(1001);
	}
	
	std::cin >> q;
	
	for(int i=0;i<q;++i){
		std::cin >> a >> b;
		
		for(int x=1;x<=a.length();++x){
			for(int y=1;y<=b.length();++y){
				if(a[x-1] == b[y-1]){
					dp[x][y] = std::max(std::max(dp[x - 1][y - 1] + 1, dp[x][y - 1]), dp[x - 1][y]);
				}else{
					dp[x][y] = std::max(std::max(dp[x - 1][y - 1], dp[x][y - 1]), dp[x - 1][y]);
				}
			}
		}
		std::cout << dp[a.length()][b.length()] << std::endl;
	}
	
	return 0;
}

C++: #include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e9;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll q; cin >> q;
    rep(Q, q){
        string s, t; cin >> s >> t;
        ll s_size = s.size(), t_size = t.size();

        vector<vector<ll>> dp(s_size+1, vector<ll>(t_size+1));

        for(ll i = 0; i < s_size; i++){
            for(ll j = 0; j < t_size; 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]);
                }
            }
        }

        cout << dp[s_size][t_size] << endl;

    }

}

C++: #include <iostream>
#include <cstring>
using namespace std;
char sz1[1000];
char sz2[1000];
int maxLen[1000][1000];
int main(){
int n;
cin>>n;
while( cin >> sz1 >> sz2 ){
int length1 = strlen( sz1);
int length2 = strlen( sz2);
int nTmp;
int i,j;
for( i = 0;i <= length1; i ++ )
maxLen[i][0] = 0;
for( j = 0;j <= length2; j ++ )
maxLen[0][j] = 0;
for( i = 1;i <= length1;i ++ ) {
for( j = 1; j <= length2; j ++ ){
if( sz1[i-1] == sz2[j-1] )
maxLen[i][j] = maxLen[i-1][j-1] + 1;
else
maxLen[i][j] = max(maxLen[i][j-1],maxLen[i-1][j]);
}
}
cout << maxLen[length1][length2] << endl;
n--;
if(n<1)break;
}
return 0;
}