Go: package main

import (
	"fmt"
)

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

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

C++: #include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}

const int N_MAX=1001,Q_MAX=150;
char X[Q_MAX][N_MAX],Y[Q_MAX][N_MAX],x[N_MAX],y[N_MAX];
int ans[Q_MAX],q,dp[N_MAX][N_MAX];

int rec(int i,int j,int k){
    if(dp[i][j]>=0)return dp[i][j];
    int res;
    if(i==0||j==0){
        res=0;
    }else if(X[k][i-1]==Y[k][j-1]){
        res=rec(i-1,j-1,k)+1;
    }else{
        res=max(rec(i-1,j,k),rec(i,j-1,k));
    }
    return dp[i][j]=res;
}

int main(){
    int i;
    //入力
    cin>>q;
    rep(i,q){
        cin>>X[i];
        cin>>Y[i];
    }
    //処理
    rep(i,q){
        memset(dp,-1,sizeof(dp));
        cout<<rec(strlen(X[i]),strlen(Y[i]),i)<<endl;
    }
    //出力
}

C++: #include <stdio.h>
#include <string.h>
#define N 1010
char a[N];
char b[N];
int dp[N][N];
//int LCS(int i, int j){
//    if(i == -1 || j == -1) return 0;
//    if(a[i] == b[j]) return LCS(i-1, j-1) + 1;
//    else return LCS(i-1, j) > LCS(i, j-1) ? LCS(i-1, j) : LCS(i, j-1);
//}
int main(){
    int k;
    scanf("%d", &k);
    while(k--){
        scanf("%s", a);
        scanf("%s", b);
        int n = strlen(a);
        int m = strlen(b);
        for(int i = n-1; i >= 0; i--) a[i+1] = a[i];
        for(int i = m-1; i >= 0; i--) b[i+1] = b[i];
        int max = n > m ? n : m;
        for(int i = 0; i <= max; i++) dp[0][i] = dp[i][0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(a[i] == b[j]) dp[i][j] = dp[i-1][j-1] + 1;
                else {
                    dp[i][j] = dp[i-1][j] > dp[i][j-1] ? dp[i-1][j] : dp[i][j-1];
                }
            }
        }
        printf("%d\n", dp[n][m]);
        //printf("%d\n", LCS(strlen(a)-1, strlen(b)-1));
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#define _USE_MATH_DEFINES // M_PI????????????????????????
#include<math.h>
#pragma warning(disable:4996)
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; // X[0]?????????????????\
	Y = ' ' + Y; // Y[0]?????????????????\

	for(int i=1; i<=m; i++){
		for(int j=1; j<=n; j++){
			if( X[i]==Y[i] ){
				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) << "\n";
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

string str1;
string str2;
int len1;
int len2;

vvector<int> dp;

int func(int p1, int p2){
	if(p1==len1||p2==len2)return 0;
	if(dp[p1][p2]>=0)return dp[p1][p2];
	int res = 0;
	if(str1[p1]==str2[p2])res = 1 + func(p1+1, p2+1);
	chmax(res, func(p1+1, p2));
	chmax(res, func(p1, p2+1));
	return dp[p1][p2] = res;
}

int main(){
	int n;
	cin >> n;
	rep(i, n){
		cin >> str1 >> str2;
		len1 = str1.size();
		len2 = str2.size();
		dp.assign(len1, vector<int>(len2, -1));
		cout << func(0, 0) << endl;
	}
	return 0;
}

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

int main()
{
	int n;
	string a, b;

	while (n--)
	{
		int memo1[1005] = {};
		int memo2[1005] = {};
		cin >> a >> b;

		for (int i = 1; i <= a.size(); i++)
		{
			memo2[0] = 0;
			for (int j = 1; j <= b.size(); j++)
			{
				if (a[i] == b[j])
					memo2[j] = max({ memo2[j - 1], memo1[j], memo1[j - 1] + 1 });
				else
					memo2[j] = max(memo2[j - 1], memo1[j]);
			}
			swap(memo1, memo2);
		}

		cout << memo1[b.size()] << endl;
	}

	return 0;
}