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 <iostream>
#include <algorithm>
using namespace std;

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

string str1, str2;
int dp[1001][1001];

void solve()
{
  REP(i, str1.size())
    if(str1[i] == str2[str2.size() - 1])
      dp[i][str2.size() - 1] = 1;
    else
      dp[i][str2.size() - 1] = 0;
  for(int i = str2.size() - 2; i >= 0; i--)
    if(str1[str1.size() - 1] == str2[i])
      dp[str1.size() - 1][i] = 1;
    else
      dp[str1.size() - 1][i] = dp[str1.size() - 1][i + 1];
  for(int i = str1.size() - 2; i >= 0; i--){
    for(int j = str2.size() - 2; j >= 0; j--){
      if(str1[i] == str2[j])
	dp[i][j] = dp[i + 1][j + 1] + 1;
      else
	dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
    }
  }
}
  
int main()
{
  int q, m = 0;
  cin >> q;
  cin.ignore();
  REP(i, q){
    getline(cin, str1);
    getline(cin, str2);
    fill(&dp[0][0], &dp[1001][0], -1);
    solve();
    REP(i, str1.size())
      m = (dp[i][0] > m) ? dp[i][0] : m; 
    cout << m << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int lcs(string x, string y)
{
	x = " " + x;
	y = " " + y;
	int n = x.size();
	int m = y.size();

	int dp[1100][1100];
	memset(dp, 0, sizeof(dp));

	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
				continue;
			}
			if (x[i] == y[j]){
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	return dp[n][m];
}

int main()
{
	int q;
	for (int i = 0; i < q; i++) {
		string s1, s2;
		cout << lcs(s1, s2) << endl;
	}

	return 0;
}

C++: 
#include <bits/stdc++.h>

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    vector<int> ans;
    rep(i,0,n){
        string s1,s2;
        cin>>s1>>s2;
        int c[1001][1001];
        int s1len=s1.size(),s2len=s2.size(),ma=0;
        s1=" "+s1;s2=" "+s2;
        rep(j,0,s1len) c[j][0]=0;
        rep(j,1,s2len)c[0][j]=0;
        rep(k,1,s1len+1){
            rep(z,1,s2len+1){
                if(s1[k]==s2[z]) c[k][z]=c[k-1][z-1]+1;
                else c[k][z]=max(c[k-1][z],c[k][z-1]);
                ma=max(ma,c[k][z]);
            }
        }
        ans.push_back(ma);
    }
    for(auto i:ans)cout<<i<<endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    while(n)
    {
        n--;
        string X,Y;
        int i=0,j=0;
        cin >> X;
        cin >> Y;
        int L[1001][1001];
        for(i=0;i<1001;i++)
            for(j=0;j<1001;j++)
               L[i][j]=0;
        for(i=1;i<=X.size();i++)
            for(j=1;j<=Y.size();j++)
            {
                if(X[i-1]==Y[j-1])
                    L[i][j]=1+L[i-1][j-1];
                else    L[i][j]=max(L[i][j-1],L[i-1][j]);
            }
        cout << L[X.size()][Y.size()] << endl;
    }
    return 0;
}