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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dp[1001][1001];

int main(void){
  ios_base::sync_with_stdio(0);
  int N;  cin >> N;
  while(N--){
    string a, b;  cin >> a >> b;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < a.size(); i++){
      for(int j = 0; j < b.size(); j++){
        if(a[i] == b[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[a.size()][b.size()] << endl;
  }
  return 0; 
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>
#include<set>

constexpr auto PI = 3.14159265359;

using namespace std;

int main() {
	int q;
	string x;
	string y;
	cin >> q;

	

	for (int k = 0; k < q; ++k) {
		cin >> x;
		cin >> y;
		x = ' ' + x;
		y = ' ' + y;
		vector<vector<int>> LCS(x.length() + 1, vector<int>(y.length() + 1, 0));

		for (int i = 1; i < x.length(); ++i) {
			for (int j = 1; j < y.length(); ++j) {
				if (x[i] == y[j]) {
					LCS[i][j] = LCS[i - 1][j - 1] + 1;
				}
				else {
					LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]);
				}
			}
		}
		cout << LCS[x.length() - 1][y.length() - 1] << endl;
	}


	return 0;
}

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

int main(){
  vector <vector<int> > dp;
  string x,y;
  int n;

  cin >> n;
  for(int times=0;times<n;times++){
    int ans =0;

    cin >> x >> y;
    dp.resize(y.size()+1);
    for(int i=0;i<=y.size();i++){
      dp[i].resize(x.size()+1);
    }

    for(int i=0;i<=y.size();i++){
      dp[i][0]=0;
    }
    for(int i=0;i<=x.size();i++){
      dp[0][i]=0;
    }

    for(int i=1;i<=y.size();i++){
      for(int j=1;j<=x.size();j++){
        if(x[j-1]==y[i-1]){
          dp[i][j] = dp[i-1][j-1]+1;
        }else{
          dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
	ans = max(ans,dp[i][j]);
      }
    }

    cout << ans << endl;
  }
}

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

#define MAX 100

using namespace std;

int lcs(string s1, string s2) {
    int C[MAX+1][MAX+1];
    int m = s1.size();
    int n = s2.size();
    for (int i = 0; i <= m; ++i) {
        C[i][0] = 0;
    }
    for (int j = 0; j <= n; ++j) {
        C[0][j] = 0;
    }

    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (s1[i-1] == s2[j-1]) {
                C[i][j] = C[i-1][j-1] + 1;
            }
            else {
                C[i][j] = max(C[i][j-1], C[i-1][j]);
            }
        }
    }

    return C[m][n];
}

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

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 0;

	int ans = 0;
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (s1[i] == s2[j])
				c[i][j] = c[i - 1][j - 1] + 1;
			else
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			ans = max(ans, c[i][j]);
		}
	}
	return ans;
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		scanf("%s %s", s1, s2);
		printf("%d\n", lcs(s1, s2));
	}

	return 0;
}

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

static const int ra =1000;

int lcs(string A, string B){
  int ca[ra+1][ra+1];
  int mi =A.size();
  int ni = B.size();
  int most = 0;

  A = ' ' + A;
  B = ' '+B;

  for(int i=1;i<=mi;i++){
    ca[i][0]=0;
  }
  for(int j=0;j<=ni;j++){
    ca[0][j] = 0;
  }

  for(int i =1;i<=mi;i++){
    for(int j=1;j<=ni;j++){
      if(A[i] == B[j]){
	ca[i][j] = ca[i-1][j-1]+1;
      }
      else{
	ca[i][j] = max(ca[i-1][j],ca[i][j-1]);
      }
      most = max(most,ca[i][j]);
    }
  }
  return most;
}

int main(){
  string K1,K2;
  int num,i;
  cin >>num ;
  for(i=0;i<num;i++){
    cin >> K1 >> K2;
    cout << lcs(K1,K2) << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define NIL -1
using namespace std;

int count(const string& X, int i, const string Y, int j,
          vector<vector<int> >& MEMO){
    if (i >= X.size() || j >= Y.size()) return 0;
    if (MEMO[i][j] != NIL) return MEMO[i][j];
    int next_X = count(X, i + 1, Y, j, MEMO);
    int j_next = Y.find(X[i], j);
    if (j_next == string::npos) return MEMO[i][j] = next_X;
    int saiyou = count(X, i + 1, Y, j_next + 1, MEMO) + 1;
    return MEMO[i][j] = max(saiyou, next_X);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        vector<vector<int> > MEMO(X.size(), vector<int>(Y.size(), NIL));
        cout << count(X, 0, Y, 0, MEMO) << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main()
{
    int q;
    cin>>q;
    vector<int>ansvec(q);
    int count=0;
    while (count<q)
    {string x,y;
     cin >> x>>y;
     vector<vector<int>>dp(x.size()+1,vector<int>(y.size()+1));
     rep(i,x.size())
     {
         rep(j,y.size())
         {
             dp[i+1][j+1]= (x[i]==y[j]) ? dp[i][j]+1 : max(dp[i+1][j],dp[i][j+1]) ;
         }
     }
     ansvec[count]=dp[x.size()][y.size()];
     count++;
    }
    
    rep(i,q)
    {
        cout<<ansvec[i]<<endl;
    }
   
    return 0;
}