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;

string X;
string Y;

int calc(int x_s, int x, int y, int length){
    if (X[x] == '\0') return length;
    int y_ = Y.find(X[x], y);
    if (y_ == string::npos) {
        if ((Y[y+1] == '\0')) {
            return max(length, calc(x_s + 1, x_s + 1, 0, 0));
        }
        return max(length, calc(x_s, x, y + 1, length));
    }
    return calc(x_s, x + 1, y_ + 1, length + 1);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        cout << calc(0, 0, 0, 0) << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
using namespace std;
#define MAXQ 150
#define MAXL 1000

int main(){
    int n; cin >> n;
    pair<string, string> pairs[MAXQ];
    for(int i=0; i<n; ++i){
        cin >> pairs[i].first >> pairs[i].second;
    }
    
    for(int i=0; i<n; ++i){
        string str1, str2;
        str1 = pairs[i].first;
        str2 = pairs[i].second;
        int dp[MAXL][MAXL];
        for(int r=0; r<=str1.size(); ++r){
            dp[r][0] = 0;
        }
        for(int c=0; c<=str2.size(); ++c){
            dp[0][c] = 0;
        }
        for(int r=1; r<=str1.size(); ++r){
            for(int c=1; c<=str2.size(); ++c){
                int d = 0;
                if (str1[r] == str2[c]) d++;
                dp[r][c] = max(dp[r-1][c-1]+d, max(dp[r-1][c], dp[r][c-1]));
            }
        }
        cout << dp[str1.size()][str2.size()] << endl;
    }
}

C++: #include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    //dp[i][j] Xのi文字目までとYのj文字目までのLCS
    int q;
    cin >> q;
    rep(i, q) {
        string X, Y;
        cin >> X >> Y;
        int m = X.size(), n = Y.size();
        vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
        rep(j, m) {
            rep(k, n) {
                if (X[j] == Y[k]) {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                } else {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }
            }
        }
        cout << dp[m][n] << "\n";
    }
}

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

int main(){
    int N;
    cin >> N;
    for(int c=0; c<N; ++c){
        string X,Y;
        cin >> X >> Y;

        int DP[1024][1024] = {};

        for(int i=0;i<=(int)X.size();++i){
            for(int j=0;j<=(int)Y.size();++j){
                if(X[i] == Y[j]){ // 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]);
                }
            }
        }
        cout << DP[(int)X.size()][(int)Y.size()] << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << ((sizeof...(tail)!=0)?" ":""); print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a << ((&a!=&vec.back())?" ":""); } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }

int dp[1010][1010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    rep(_, n) {
        string s, t; cin >> s >> t;
        memset(dp, 0, sizeof(dp));
        int n = s.length(), m = t.length();
        rep(i, n) rep(j, m) {
            char a = s[i], b = t[j];
            if (a==b) 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[n][m] << endl;
    }
}

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

using namespace std;

static const int N = 1000;

int lcs(string X, string Y){
	int c[N + 1][N + 1];
	int m = X.xize();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	
	for(int i = 1; i <= m; i++)
	c[i][0] = 0;
	
	for(int j = 1; j <= n; j++)
	c[0][j] = 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 {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl,c[i][j]);
		}
	}
	
	return maxl;
}


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

C++: #include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;

int lcs(string X, string Y){
  
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  for ( int i=1; i<=m; i++) c[i][0]=0;
  for ( int j=1; j<=n; j++) c[0][j]=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{
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      maxl=max(maxl,c[i][j]);
    }
  }

  return maxl;
}

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