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<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 = 0;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;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int Tc; cin >> Tc;
  
  while(Tc--) {
    string s, t; cin >> s >> t;
    
    int dp[1001][1001] = {{}};
    
    int const 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]);
        }
      }
    }
    
    cout << dp[N][M] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstring>

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

template<class T>
bool chmax(T &a, const T &b) {
    if(a<b) {
        a=b;
        return false;
    }
    return true;
}

using namespace std;

int dp[1003][1003];
int main() {
    int q; cin>>q;
    rep(_,q) {
        memset(dp,0,sizeof(dp));
        string s,t;
        cin>>s>>t;
        s=" "+s;
        t=" "+t;
        rep(i,s.size()){
            rep(j,t.size()) {
                if(i&&j) {
                    if(s[i]==t[j]) dp[i][j]=dp[i-1][j-1]+1;
                    else {
                        chmax(dp[i][j],dp[i-1][j]);
                        chmax(dp[i][j],dp[i][j-1]);
                    }
                }
            }
            //rep(j,t.size()) cout<<dp[i][j]<<" ";
            //cout<<endl;
        }
        int ans=0;

        rep(i,s.size()) chmax(ans,*max_element(dp[i],dp[i]+t.size()));
        cout<<ans<<endl;
    }

    return 0;
}

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

#define N 1000

int lcs(string X,string Y){
	int c[N+1][N+1];
	int m = X.size();
	int n = Y.size();
	for(int i=0;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++){
			if(X[i]==Y[j]){
				c[i][j] = c[i-1][j-1]+1;
			}else if(c[i][j-1]>=c[i-1][j]){
				c[i][j] = c[i][j-1];
			}else{
				c[i][j] = c[i-1][j];
			}
		}
	}
	return c[m][n];
}

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

C++: #include <bits/stdc++.h>
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 = 0; 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;

}

C++: #include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef double db;
typedef string str;
// head

void solve(){
    str s,t;
    cin>>s>>t;
    int S=s.size();
    int T=t.size();
    int dp[1010][1010];
    range(i,S){
        range(j,T){
            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]);
            }
        }
    }
    cout<<dp[S][T]<<endl;
}

int main(){
    int n;
    cin>>n;
    range(i,n)
    solve();
}

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

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

// 最長共通部分列 ... len(s) == m, len(t) == n とすると, O(mn)
int lcs(std::string s, std::string t) {
  std::vector<std::vector<int> > dp(s.size() + 1, std::vector<int>(t.size() + 1, 0));

  for (int i = 0; i < s.size(); ++i) {
    for (int j = 0; j < t.size(); ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = (i == 0 ? (j == 0 ? 1 : 0) : 0);
      }
      else if (i >= 0 && j >= 0 && dp[i - 1][j] >= dp[j][i - 1]) {
        dp[i][j] = dp[i - 1][j];
      }
      else if (i >= 0 && j >= 0) {
        dp[i][j] = dp[i][j - 1];
      }
    }
  }

  return dp[s.size()][t.size()];
}

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

  return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

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

int main() {
    int num; cin >> num;
    rep(k,0,num) {
        string s1,s2;
        cin >> s1 >> s2;

        int dp[101][101]; //s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
        int n = s1.length();
        int m = s2.length();
        rep(i,0,m+1) dp[0][i] = 0;

        rep(i,0,n) {
            rep(j,0,m) {
                if(s1[i]==s2[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]);
            }
        }
        cout << dp[n][m] << endl;
    }
    return 0;
}

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

#define MAX 1000

int lcs(string X, string Y) {
    int c[MAX+1][MAX+1];
    int m = X.size();
    int n = Y.size();
    int i, j;
    int maxlen = 0;
    X = " " + X;
    Y = " " + Y;

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

    for(i = 1 ; i <= m ; i++ ) {
        for(j = 1 ; j <= n ; j++ ) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i-1][j-1] + 1;
            }else if( c[i-1][j] >= c[i][j-1] ) {
                c[i][j] = c[i-1][j];
            }else {
                c[i][j] = c[i][j-1];
            }
            maxlen = max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}

int main (void) {
    int N, i;
    string x, y;
    

    cin >> N;

    for(i = 0 ; i < N ; i++) {
        cin >> x;
        cin >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}