Go: package main

import "fmt"

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

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

C++: #include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
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; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく
int N;
vector<int> E[200001];
bool shipment[15][15];
vector<bool> seen;
typedef pair<int, int> P;
int D[101];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;
int dp[1001][1001];

void solve_LCS(string X,string Y) {
    int S = X.size();
    int T = Y.size();
    for (int i = 0; i < S; i++) {
        for (int j = 0; j < T; j++) {
            //同じ文字だったら、max(今まで+1,今までの最大)をする
            if (X[i] == Y[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 + 1][j], dp[i][j + 1]);
        }
    }

    cout << dp[S][T] << endl;
}

int main() {
    int Q; cin >> Q;
    vector<string> Xs(Q);
    vector<string> Ys(Q);
    for (int i = 0; i < Q; i++) {
        cin >> Xs.at(i) >> Ys.at(i);
    }
    for (int i = 0; i < Q; i++) {
        solve_LCS(Xs.at(i),Ys.at(i));
    }
}

C++: #include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#define MAX 10001

using namespace std;

int c[MAX][MAX]; 
int n, m;
int maxlengh;

int lcs(string A, string B) {
	maxlengh = 0;
	A = ' ' + A;
	B = ' ' + B;
	n = A.size();
	m = B.size();

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i == 0 || j == 0) {
				c[i][j] = 0;
			}else if(A[i] == B[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			}else{
				c[i][j] = max(c[i][j - 1], c[i - 1][j]);
			}maxlengh = max(maxlengh, c[i][j]);
		}
	}
	return maxlengh;
}

int main() {
	int q;
	cin >> q;
	string a, b;
	
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		cout << lcs(a, b) << endl;
	}
	return 0;
}

C++: //#define		FILE_INPUT_DEFINE
#ifdef		FILE_INPUT_DEFINE
#include	<fstream>
#endif		// FILE_INPUT_DEFINE

#include	<iostream>
#include	<string>
#include	<algorithm>

using namespace std;

#define			MAX		1000
#define			ind(x)		((x) - 1)

int C[MAX][MAX];

int LCS(string &X, string &Y)
{
	int			Xlen = X.length();
	int			Ylen = Y.length();

	for (int i = 0; i <= Xlen; ++i)
	{
		C[i][0] = 0;
	}

	for (int i = 0; i <= Ylen; ++i)
	{
		C[0][i] = 0;
	}

	for (int i = 1; i <= Xlen; ++i)
	{
		for (int j = 1; j <= Ylen; ++j)
		{
			if (X[ind(i)] == Y[ind(j)])
			{
				C[i][j] = C[i - 1][j - 1] + 1;
			}
			else
			{
				C[i][j] = max(C[i - 1][j], C[i][j - 1]);
			}
		}
	}

	return (C[Xlen][Ylen]);
}

int main()
{
#ifdef		FILE_INPUT_DEFINE
	// input from txt
	std::ifstream in(R"(C:\Temp\input.txt)");
	std::cin.rdbuf(in.rdbuf());
#endif		// FILE_INPUT_DEFINE

	string	X, Y;
	int		n;

	cin >> n;
	cin.clear();
	cin.ignore();

	for (int i = 0; i < n; ++i)
	{
		getline(cin, X);
		getline(cin, Y);

		cout << LCS(X, Y) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

void solve() {
	string x, y;
	cin >> x >> y;
	int xlen = x.length();
	int ylen = y.length();
	int dp[155][155];
	dp[0][0] = 0;

	for (int i = 0; i <= xlen; i++) {
		for (int j = 0; j <= ylen; j++) {
			if (i == 0 || j == 0) {
				dp[i + 1][j + 1] = 0;
			}
			else if (x[i - 1] == y[j - 1]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	cout << dp[xlen + 1][ylen + 1] << endl;
}
int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)solve();
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  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 if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

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

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

  return 0;
}

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

template<class T>
T myMin(const T& arg){
	return arg;
}
template<class F, class... S>
F myMin(const F& first, const S&... second){
	F m = myMin(second...);
	if (m > first){
		return first;
	}else{
		return m;
	}
}
int f(std::string::iterator str1, const std::string& str2, const std::vector<int>& vec){
	std::vector<int> new_v;
	new_v.push_back(vec[0] + 1);
	{
		auto v = vec.begin() + 1;
		for (auto i = str2.begin(); i != str2.end(); ++i, ++v){
			if (*i == *str1){
				new_v.push_back(*(v - 1));
			}else{
				new_v.push_back(myMin(*v + 1, new_v.back() + 1));
			}
		}
	}
	if (*(++str1) != '\0'){
		return f(str1, str2, new_v);
	}else{
		return new_v.back();
	}
}
int main(){
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i){
		std::string str1, str2;
		std::cin >> str1 >> str2;
		std::vector<int> vec;
    vec.push_back(0);
		for (int j = 0; j < str2.size(); ++j){
			vec.push_back(j);
		}
		std::cout << (str1.size() + str2.size() - f(str1.begin(), str2, vec)) / 2 << "\n";
	}
}