Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
#include <vector>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


vector<string> getCombinations(string str, int len)
{
  assert(0 < len && len <= str.length());

  vector<string> combinations;

  if (len == 1)
  {
    for (int i = 0; i < str.length(); i++)
      combinations.push_back(str.substr(i, 1));

    return combinations;
  }

  for (int i = 0; i <= str.length() - len; i++)
  {
    const char c = str[i];
    vector<string> recursive = getCombinations(str.substr(i+1), len - 1);

    for (string str : recursive)
      combinations.push_back(c + str);
  }

  return combinations;
}


bool findCombination(string src, string find)
{
  vector<string> combinations = getCombinations(src, find.length());

  for (string str : combinations)
  {
    if (str == find)
      return true;
  }

  return false;
}


int getLCSlen(string s0, string s1)
{
  const string* pStrLong;
  const string* pStrShort;

  if (s0.length() < s1.length())
  {
    pStrShort = &s0;
    pStrLong = &s1;
  }
  else
  {
    pStrShort = &s1;
    pStrLong = &s0;
  }


  const int kLenInvalid = -1;
  int longestLen = kLenInvalid;
  int len = pStrShort->length();

  while (longestLen == kLenInvalid && len > 0)
  {

    vector<string> candidates = getCombinations(*pStrShort, len);

#if DEBUG & 0
    for (string str : candidates)   DPRINTF("%s\n", str.c_str());
#endif // DEBUG

    for (string candidate : candidates)
      if (findCombination(*pStrLong, candidate))
        longestLen = len;

    len--;

  }

  return longestLen;
}


int main()
{
  int numOfPair;
  cin >> numOfPair; cin.ignore();

  DPRINTF("num of pair %d\n", numOfPair);

  for (int i = 0; i < numOfPair; i++)
  {
    string str0, str1;
    cin >> str0 >> str1; cin.ignore();

    DPRINTF("str0 %s  str1 %s\n", str0.c_str(), str1.c_str());

    cout << getLCSlen(str0, str1) << 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=1;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<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
//union_find
int par[100];
int depth[100];
ll N;
ll x[20],c[20],v[20];
string s,t;

int lcs(string x, string y){
    int dp[1010][1010];
    int m = s.size();
    int n = t.size();
    int mx = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i = 0; i <= m; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = 0;
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(x[i] == y[i]){
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
            mx = max(mx, dp[i][j]);
        }
    }
    return mx;
}
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s >> t;
        cout << lcs(s,t) << endl;
    }
}

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

int dp[1010][1010];

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

  cin >> q;

  for(int t = 0;t < q;t++){
    cin >> x;
    cin >> y;

    memset(dp, 0, sizeof(dp));
    
    for(int i = 1;i <= x.size();i++){
      for(int j = 1;j <= y.size();j++){

	if(x[i-1] == y[j-1]){
	  dp[i][j] = dp[i-1][j-1]+1;
	}
	else if(dp[i-1][j] <= dp[i][j-1]){
	  dp[i][j] = dp[i][j-1];
	}
	else{
	  dp[i][j] = dp[i-1][j];
	}
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int q;
  cin >> q;
  while (q--) {
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.size();
    vector<vector<int> > dp(n + 1, vector<int>(m + 1));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (x[i] == y[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[n][m] << 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, i, j;

  x = ' ' + x;
  y = ' ' + y;

  for(i=0;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]);
      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;
}