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>
#define N 1000
using namespace std;

int lcs(string x, string y){
  int m = x.size();
  int n = y.size();
  int maxsize = 0;
  int c[N + 1][N + 1];

  x = ' ' + x;
  y = ' ' + y;

  for(int i = 1; i < m; i++){
    c[i][0] = 0;
  }

  for(int i = 0; i < n; i++){
    c[0][i] = 0;
  }

  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 if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }

      else{
	c[i][j] = c[i][j-1];
      }

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

    }
  }

  return maxsize;
  
}

int main()
{
  int n;
  cin >> n;

  string x, y;

  for(int i = 0; i < n; i++){
    cin >> x >> y;

    cout << lcs(x, y) << endl;
    
  }

  return 0;

}

C++: //#if 0
//????????????????§£?????????????????????????????????????????????????????????C++??§string??????????????§???
//?????????????????§???????????§???AOJ?????????????????????Runtime Error??????????????????????????????
//??£????????¨??????????????????????????????????????????????????????Runtime Error???????????¨???????????????
//??§???????????????????????????????????§???
//#endif
#include<iostream>
#include<string>
#define lth 1010

using namespace std;

int main()
{
	int n, L[1010][1010], Lmax = 0, *save;
	string *Xi, *Yi;
	cin >> n;
	save = new int[n];
	if (n <= 20)
	{
		Xi = new string[lth];
		Yi = new string[lth];
	}
	else
	{
		Xi = new string[1010];
		Yi = new string[1010];
	}
	for (int k = 0; k < n; k++)
	{
		Lmax = 0;
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}

	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll q;
    cin >> q;
    rep(i, q) {
        string s, t;
        cin >> s >> t;
        ll n = s.size(), m = t.size();
        ll dp[1100][1100] = {0};
        rep(i, n) rep(j, m) {
            if(s[i] == t[j]) dp[i+1][j+1] = max({dp[i][j] + 1, dp[i+1][j], dp[i][j+1]});
            else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
        cout << dp[n][m] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1005;
inline int lcs(string X, string Y) {
	vv(int, c, MAX, MAX, 0);
	int m = len(X);
	int n = len(Y);
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	rep(i, 1, m + 1) {
		rep(j, 1, n + 1) {
			if(X[i] == Y[j]) c[i][j] = c[i - 1][j - 1] + 1;
			else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			if(maxl < c[i][j]) maxl = c[i][j];
		}
	}
	return maxl;
}
int main() {
	int n; cin >> n;
	string s1, s2;
	rep(i, 0, n) {
		cin >> s1 >> s2;
		P(lcs(s1, s2));
	}
	return 0;
}

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

using namespace std;
static const int N=1000;
int lcs(string X, string Y){
    int m=X.size();
    int n=Y.size();
    int c[N+1][N+1];
    int maxl=0;
    X=' '+X;
    Y=' '+Y;
    int i,j;
    for(i=1;i<=m;i++)c[i][0]=0;
    for(j=1;j<=n;j++)c[0][j]=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{
                c[i][j]=max(c[i][j-1],c[i-1][j]);
            }
            maxl=max(maxl,c[i][j]);
        }
    }
    return maxl;
}
int main()
{
    int n;
    string s1,s2;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }

    return 0;
}

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

int lcs(string s, string t);
int main(){
  int n; cin >> n;
  string s, t;
  for(int i=0; i<n; i++){
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }

  return 0;
}

int lcs(string s, string t){
  int ans=0;
  int sl=s.length(), tl=t.length();
  int dp[s.length()+1][t.length()+1];
  dp[0][0]=0;
  for(int i=1; i<=sl; i++) dp[i][0]=0;
  for(int j=1; j<=tl; j++) dp[0][j]=0;

  for(int i=1; i<=sl; i++){
    for(int j=1; j<=tl; j++){
      if(i==0 || j==0) dp[i][j]=0;
      else if(s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
      else dp[i][j]=max(dp[i][j-1], dp[i-1][j]);

      ans = max(ans, dp[i][j]);
    }

  }
  return ans;
}