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 REP0(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define REPB0(i,n) for(int i=n-1;i>=0;i--)
#define REPB1(i,n) for(int i=n;i>0;i--)
#define llong long long
#define INF 2000000000
#define NIL -1
#define N 1000
using namespace std;
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;
  REP1(i,m) C[i][0]=0;
  REP1(i,n) C[0][i]=0;
  REP1(i,m){
    REP1(j,n){
      if(X[i]==Y[j]) C[i][j]=C[i-1][j-1]+1;
      else C[i][j]=max(C[i-1][j],[i][j-1]);
      maxl=max(maxl,C[i][j]);
    }
  }
  return maxl;
}
int main(){
  char a[1000],b[1000];
  string s1,s2;
  int n;
  scanf("%d",&n);
  REP0(i,n){
    scanf("%s %s",a,b);
    s1=a,s2=b;
    printf("%d\n",LCS(s1,s2));
  }
  return 0;
}

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

std::string x,y;
int lcs[1000][1000] = {0};

int max(int k,int l){
  if(k>l){
    return k;
  }else{
    return l;
  }
}

void LCS(int i,int 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]);
  }
}

void pre(){
  for(int i=0;i<(int)y.size();i++){
    if(x[0] == y[i]){
      lcs[0][i] = 1;
    }else{
      lcs[0][i] = 0;
    }
    if(x[i] == y[0]){
      lcs[i][0] = 1;
    }else{
      lcs[i][0] = 0;
    }
  }
}

int main(){
  int q;
  std::cin >> q;
  for(int k=0;k<q;k++){
    std::cin >> x;
    std::cin >> y;
    int size_x=x.size(),size_y=y.size();
    pre();
    for(int i=1;i<size_x;i++){
      for(int j=1;j<size_y;j++){
	LCS(i,j);
      }
    }

    /*for(int i=0;i<size_x;i++){
      for(int j=0;j<size_y;j++){
	std::cout << lcs[i][j] << ' ';
      }
      std::cout << '\n';
    }
    */
    std::cout << lcs[size_x-1][size_y-1] << '\n'; 

  }
  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))

int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }

int main() {
	int n, m, a, dp[102][102] = { 0 };
	char s[1001], t[1001];
	scanf("%d", &a);
	for (int k = 0; a > k; k++) {
		scanf("%s %s", s, t);
		n = strlen(s);
		m = strlen(t);
		for (int i = 1; n >= i; i++) {
			for (int j = 1; m >= j; j++) {
				if (s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
				else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
		printf("%d\n", dp[n][m]);
	}
	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_Y = count(X, i    , Y, j + 1, MEMO);
    int next_X = count(X, i + 1, Y, j    , MEMO);
    int max_ = max(next_Y, next_X);
    int j_tmp = j;
    while (X[i] != Y[j_tmp]) {
        j_tmp++;
        if (j_tmp >= Y.size()) return max_;
    }
    int saiyou = count(X, i + 1, Y, j_tmp + 1, MEMO) + 1;
    if (max_ < saiyou) max_ = saiyou;
    return MEMO[i][j] = max_;
}

int solve(const string& X, const string& Y) {
    int max = 0;
    vector<vector<int> > MEMO(X.size(), vector<int>(Y.size(), NIL));
    for (int i = 0; i < X.size(); i++) {
        int c = count(X, i, Y, 0, MEMO);
        if (c > max) max = c;
    }
    return max;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        cout << solve(X, Y) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <string>
#include <climits>
using namespace std;

int lcs(string& x, string& y)
{
    int i, j, m = x.length(), n = y.length();
    vector<vector<int> > c(m + 1, vector<int>(n + 1));
    x.insert(x.begin(), ' ');
    y.insert(y.begin(), ' ');
    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
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
        }
    }
    return c[m][n];
}

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

C++: #include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
using namespace std;



int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string a, b;
		cin >> a >> b;
		if (a.size() < b.size())swap(a, b);
		
		int ans = 0;
		for (int k = 0; k < a.size(); k++)
		{
			for (int s = 0; s <= a.size() - b.size(); s++)
			{
				int sum = 0;
				for (int j = 0; j < b.size(); j++)
				{
					if (a[j + s] == b[j])sum++;
				}
				ans = max(sum, ans);
			}
		}
		cout << ans << endl;

		



	}



}

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

int lcs(string X, string Y){
    int C[1001][1001];
    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 i=0; 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{
                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;
}