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<vector>
#include<algorithm>
#include<string>
using namespace std;

int LCS(string p, string q) {
	vector<vector<int>> f(p.size()+1, vector<int>(q.size()+1,0));
	int t;
	for (int i = 1; i <= p.size(); i++) {
		for (int j = 1; j <= q.size(); j++) {
			if (p[i-1] == p[j-1])
				f[i][j] = f[i - 1][j - 1] + 1;
			else if (f[i][j - 1] > f[i - 1][j - 1])
				f[i][j] = f[i][j - 1];
			else
				f[i][j] = f[i - 1][j];
		}
	}
	return f[p.size()][q.size()];
}

int main() {
	int n;
	string p[150];
	cin >> n;
	for (int i = 0; i < n; i ++) {
		cin >> p[2*i] >> p[2*i + 1];
	}
	for (int i = 0; i < n; i++) {
		cout << LCS(p[2*i], p[2 * i + 1])<<endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;

int lcs(int x_begin, int y_begin) {
	int max = 0;
	for (int i = x_begin; X[i] != '\0'; i++) {
		for (int j = y_begin; Y[j] != '\0'; j++) {
			if (X[i] == Y[j]) {
				int v_lcs = lcs(i + 1, j + 1);
				if (v_lcs + 1 > max) {
					max = v_lcs + 1;
				}
			}
		}
	}
	return max;

}

int main() {
	int N;
	cin >> N;
	string stringX, stringY;
	for (int i = 1; i <= N; i++) {
		cin >> stringX >> stringY;
		X = stringX.c_str();
		Y = stringY.c_str();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

constexpr int MAX = 1000;
char ls[MAX];
char rs[MAX];
int table[MAX + 1][MAX + 1];


void calc_lcs() {
    scanf("%s", ls);
    scanf("%s", rs);
    int l_len = int(std::strlen(ls));
    int r_len = int(std::strlen(rs));
    for (int i = 0; i < l_len; i++) {
        table[i][0] = 0;
    }
    for (int i = 0; i < r_len; i++) {
        table[0][i] = 0;
    }

    for (int l_i = 1; l_i < l_len + 1; l_i++) {
        for (int r_i = 1; r_i < r_len + 1; r_i++) {
            if (ls[l_i - 1] == rs[r_i - 1]) {
                table[l_i][r_i] = table[l_i - 1][r_i - 1] + 1;
            } else {
                table[l_i][r_i] = std::max(table[l_i][r_i - 1], table[l_i - 1][r_i]);
            }
        }
    }
    std::cout << table[l_len][r_len] << std::endl;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        calc_lcs();
    }
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define all(obj) (obj).begin(), (obj).end()
#define fi first
#define sc second
#define pb push_back
#define str to_string
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
void chmax(ll &a, ll b) { a = max(a, b); }
void chmin(ll &a, ll b) { a = min(a, b); }

ll dp[1010][1010];

ll LCS(string a, string b) {
    int N = a.size();
    int M = b.size();
    memset(dp, 0, sizeof(dp));

    rep(i, 0, N+1) rep(j, 0, M+1) {
        if (i < N) {
            chmax(dp[i+1][j], dp[i][j]);
        }
        if (j < M) {
            chmax(dp[i][j+1], dp[i][j]);
        }
        if (i < N && j < M && a[i] == b[j]) {
            chmax(dp[i+1][j+1], dp[i][j]+1);
        }
    }
    return dp[N][M];
}

int main() {
    int Q;
    string a, b;
    cin >> Q;
    rep(i, 0, Q) {
        cin >> a;
        cin >> b;
        cout << LCS(a, b) << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;

int get_LCS(string x, string y){
  int nx = x.size(), ny = y.size();
  int dp[nx+1][ny+1];
  for(int i=0;i<=ny;i++) dp[0][i] = 0;
  for(int i=0;i<=nx;i++) dp[i][0] = 0;
  for(int i=1;i<=nx;i++){
    for(int j=1;j<=ny;j++){
      if(x[i-1] == y[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
      else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
    }
  }
  /*for(int i=1;i<=nx;i++){
    for(int j=1;j<=ny;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  return dp[nx][ny];
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int q; cin >> q;
  for(int i=0;i<q;i++){
    string x, y; cin >> x >> y;
    cout << get_LCS(x, y) << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

signed main() {
  int n; cin >> n;
  string x,y;
  while(n--){
    cin >> x >> y;
    vector<vector<int> > dp(x.size()+1,vector<int>(y.size()+1));
    for(int i=0;i<x.size();++i){
      for(int j=0;j<y.size();++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]);
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }
  
  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;
 
}