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>
#include<string>
#include<cstring>
#include<cstdlib>
#define MAX_N 1000

int solve(std::string s,std::string t){
        int dp[MAX_N][MAX_N]={0};
        int n,m;
        n=s.size();
       m=t.size();
        for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                        if(s[i]==t[j])
                                dp[i+1][j+1]=dp[i][j]+1;
                        else
                                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
        }
        return dp[n][m];
}

int main(){
        int q;
        std::cin>>q;
        for(int i=0;i<q;i++){
                std::string s,t;
                std::cin >> s>>t;
                std::cout<<solve(s,t)<<std::endl;
        }
        return 0;
}

C++: #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1001
void solve(void);
int q,count[MAX][MAX]={},xlength,ylength;
char X[MAX],Y[MAX];

void solve(void){
  int i,j;

  xlength=strlen(X);
  ylength=strlen(Y);
  
  for(i=1;i<=xlength;i++){
    for(j=1;j<=ylength;j++){
      if(X[i-1]==Y[j-1]) count[i][j]=count[i-1][j-1]+1;
      else if(count[i-1][j]>=count[i][j-1]) count[i][j]=count[i-1][j];
      else count[i][j]=count[i][j-1];
    }
  }
}
    
int main()
{
  int i;
  
  scanf("%d",&q);

  for(i=1;i<=q;i++){
    scanf("%s",X);
    scanf("%s",Y);
    solve();
    printf("%d\n",count[xlength][ylength]);
  }

  /*for(i=0;i<q;i++){
    printf("%d\n",count[][]);
    }*/

  return 0;
}

C++: import sys
sys.setrecursionlimit(10000)

def calc(x,y):
    i = len(x)
    j = len(y)
    if not d[i][j] == None:
        return d[i][j]
    else:
        if x[-1] == y[-1]:
            tmp = calc(x[:-1],y[:-1])+1
            d[i][j] = tmp
            return tmp
        else:
            tmp = max(calc(x[:-1],y),calc(x,y[:-1]))
            d[i][j] = tmp
            return tmp
        
q = int(input())
for i in range(q):
    x = input()
    y = input()
    d = [[0 if i == 0 or j == 0 else None for i in range(len(y)+1)] for j in range(len(x)+1)]
    print(calc(x,y))

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int dp[1001][1001];
int solve(string a,string b)
{	
	
	int maxn=0;
	int len1=a.size(),len2=b.size();
	

	for(int i=1;i<=len1;i++)
		for(int j=1;j<=len2;j++)
		{
			if(a[i-1]==b[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else 
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);//这个只是表示某个状态的不是最大的，这个是自己设定的
			maxn=max(maxn,dp[i][j]);
		}
		return maxn;
		
		
	
}
int main()
{	int n;
	string a,b;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		cout<<solve(a,b)<<endl;
	}
	return 0;
}

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

int c[10001][10001];

int llcs(string X, string Y)
{
    //cout << "hhh" << endl;
    //cout << X << " " << Y << endl;
    int m=X.size();
    int n=Y.size();
    //cout << m << " " << n << endl;
    int maxl=0;
    X=' '+X;
    Y=' '+Y;

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


    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            //cout << i << " " << j << c[i][j] << endl;
            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()
{
    int N;
    cin >> N;
    string X,Y;
    for(int i=0;i<N;i++)
    {
        cin >> X;
        cin >> Y;
        cout << llcs(X,Y) << endl;
    }

    return 0;
}

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

string X, Y;
int q, lx, ly;
int dp[1010][1010];

int main() {
    cin >> q;
    
    for (int i=0; i<q; ++i) {
        cin >> X >> Y;
        lx = X.size();
        ly = Y.size();
        for (int i=0; i<=ly; ++i) dp[i][0] = 0;
        for (int i=0; i<=lx; ++i) dp[0][i] = 0;

        for (int j=1; j<=ly; ++j) {
            for (int k=1; k<=lx; ++k) {
                if (Y[j-1]==X[k-1]) dp[j][k] = dp[j-1][k-1] + 1;
                else dp[j][k] = max(dp[j-1][k], dp[j][k-1]);
            }
        }
        cout << dp[ly][lx] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
void solve(string s, string t){
    int l1=s.size(),l2=t.size();
    vector <vector<int>> dp(l1+10 ,vector <int>(l2+10 ));
    for(int i=0;i<l1;i++){
        for(int j=0;j<l2;j++){
            if(s[i]==t[j]) {
                dp[i+1][j+1] = max(dp[i][j] + 1, dp[i+1][j+1]);
            }else{
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    cout<<dp[l1][l2]<<endl;
}
int main(void){
    int n; cin>>n;
    for(int i=0;i<n;i++){
        string s,t; cin>>s>>t;
        solve(s,t);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int solve(string X, string Y){
  int dp[X.size()+1][Y.size()+1] = {0};
  REP(i, X.size()+1){
    REP(j, Y.size()+1){
      dp[i][j] = 0;
    }
  }
  REP(i, X.size()){
    REP(j, Y.size()){
      if(X[i] == Y[j]){
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      }
      dp[i+1][j+1] = max({dp[i+1][j+1], dp[i][j], dp[i][j+1], dp[i+1][j]});
    }
  }
  return dp[X.size()][Y.size()];
}
int main(){
  int q;
  cin >> q;
  while(q--){
    string X, Y;
    cin >> X >> Y;
    cout << solve(X, Y) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int hoge = 1000;
int C[1000][1000];
int lc(string F, string S){

    fill(C[0],C[hoge],0);
    int m = F.size(), n = S.size();
    int len=0;
    for(int i=0; i<m; i++){
        for (int j = 0; j < n; ++j) {
            if (F[i] == S[j]) {
                if (i - 1 >= 0 && j - 1 >= 0)
                    C[i][j] = C[i - 1][j - 1] + 1;
                else
                    C[i][j] = 1;
            } else if (i - 1 < 0) {
                if(j-1 < 0){
                    C[i][j] = 0;
                }else{
                    C[i][j] = C[i][j - 1];
                }
            }else if(j-1 < 0) {
                C[i][j] = C[i - 1][j];
            }else{
                C[i][j] = max(C[i-1][j], C[i][j - 1]);
            }
            len = max(len, C[i][j]);
        }
    }
    return len;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ar1,ar2;
    for (int i = 0; i < n; ++i) {
        cin >> ar1 >> ar2;
        cout << lc(ar1,ar2) << endl;
    }
    return 0;
}