Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

/*********************************************************************
長さmの列X_(m)と長さnの列Y_(n)の最長共通部分列LCSは、
	(1)X[m] == Y[n]ならば、X_(m-1)とY_(n-1)のLCSにX[m]を繋げたもの
	(2)X[m] != Y[n]ならば、X_(m-1)とY_(n)のLCSもしくはX_(m)とY_(n-1)のLCS
	のいずれかのうち長い方

c[m+1][n+1]：c[i][j]にX_(i)とY_(j)のLCSの長さを格納する二次元配列
*********************************************************************/

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); 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])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const int INF = 1e9;
const int MOD = 17;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

void solve() {
    string S,T; cin >> S >> T;
    int N = S.size(),M = T.size();
    vector<vector<int>> dp(N + 1,vector<int>(M + 1,0));
    rep(i,N)rep(j,M) {
        if (S[i] == T[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]);
    }
    printf("%d\n",dp[N][M]);
}

int main() {
    int Q; cin >> Q;
    rep(i,Q) solve();
}

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], maxl = 0, i, j;
  int m = x.size();
  int n = y.size();

  x = ' ' + x;
  y = ' ' + y;
 
  for(i = 1; i <= m; i++) c[i][0] = 0;
  for(i = 1; i <= n; i++) c[0][i] = 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 c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

int main(){
  string x, y;
  int q, i;

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

C++: #include <utility>
#include <algorithm>
#include <iostream>
#include <string>
#include <stack>
#include <cstdlib>


using namespace std;

int Q;


int main(){
  cin >> Q;
  string X,Y;
  int L[1010][1010]={0};
  int len = 0;
  for(int q=0;q<Q;++q){
    cin >> X;
    cin >> Y;
    len = X.length();
      for(int j=1;j<len+1;++j){//kkkkkkkkkkkkkkkkkkkkkkk
	for(int i=1;i<len+1;++i){
	  if(i <= 0 || j <= 0) L[i][j] = 0;
	  else if(X[i] == Y[j]) L[i][j] = 1 + L[i-1][j-1];
	  else L[i][j] = max(L[i][j-1],L[i-1][j]);
	}
      }

    cout << L[len][len] << endl;
  }
}

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

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

#define N 1000

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

  FOR(i, 1, m + 1) {
    FOR(j, 1, n + 1) {
      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]);
      }
      maxlen = max(maxlen, c[i][j]);
    }
  }

  return maxlen;
}

int main(void) {
  string X, Y;
  int n; cin >> n;
  REP(i, n) {
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
  return 0;
}

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

int lcs(string x, string y) {
	static int c[1001][1001];
	int m = x.size();
	int n = y.size();
	int max1 = 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]);
			max1 = max(max1, c[i][j]);

		}
	}
	return max1;
}

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<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 <string>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 160;

int LongestCommonSubsequence(string s1, string s2) {
    int N = (int) s1.size();
    int M = (int) s2.size();
    vector < vector < int > > dp(N + 10, vector < int > (M + 10, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            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]);
            }
        }
    }
    return dp[N][M];
}

int main(int argc, char const *argv[])
{
    int q, ans[MAX_N];
    cin >> q;
    for (int i = 0; i < q; ++i) {
        string a, b;
        cin >> a >> b;
        ans[i] = LongestCommonSubsequence(a,b);
    }

    for (int i = 0; i < q; ++i) {
        cout << ans[i] << endl;
    }
	return 0;
}

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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.shrink_to_fit();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}