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>
#include<string>
#define MAX 1001
using namespace std;

string x, y;

int c[MAX][MAX];
int lcs(int m, int n);

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

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

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

int LCS() {
    int i, j, maxl;
    string X, Y;
    int C[MAX+1][MAX+1];

    cin >> X >> Y;
    size_t X_len = X.length();
    size_t Y_len = Y.length();

    for (i=0; i<=X_len; i++) {
        for (j=0; j<=Y_len; j++) {
            if (i==0 || j==0) C[i][j]=0;
            else {
                if (X[i]==Y[j]) {
                    C[i][j]=C[i-1][j-1]+1;
                    maxl = max(C[i][j], maxl);
                } else C[i][j]=max(C[i-1][j], C[i][j]);
            }
        }
    }

    return maxl;
}

int main() {
    int n, i;
    
    cin >> n;
    for (i=0; i<n; i++) {
        printf("%d\n", LCS());
    }

    return 0;
}

C++: // 最長共通部分列
// O(|S||T|)

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()


int LongestCommonSubsequence(const string &s, const string &t) {
  int n = (int)s.size();
  int m = (int)t.size();

  vector<vector<int>> dp(n + 1, vector<int> (m + 1, 0));
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      if(s[i - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
    }
  }
  
  return dp[n][m];
}


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

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

const int N = 1000;

int lcs(string x, string y);

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

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 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 c[i][j] = max(c[i-1][j], c[i][j-1]);

      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}

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

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

using namespace std;

int n, m;
char s[1001];
char t[1001];
int dp[1001][1001];

int main(){
	int q;
	scanf("%d", &q);
	rep(z, q){
		scanf("%s%s", s, t);
		n = strlen(s);
		m = strlen(t);

		rep(i, n + 1){
			dp[i][0] = 0;
		}
		rep(i, m + 1){
			dp[0][i] = 0;
		}
		for(int i = 1; i <= n; ++i){
			for(int j = 1; j <= m ; ++j){
				dp[i][j] = max(dp[i - 1][j - 1] + (s[i - 1] == t[j - 1]), max(dp[i][j - 1], dp[i - 1][j]));
			}
		}
		printf("%d\n", dp[n][m]);
	}
	return 0;
}

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

int q;

int main(void) {
    cin >> q;

    for (int i = 0; i < q; ++i) {
        string X;
        string Y;

        cin >> X >> Y;

        int xlen = X.size();
        int ylen = Y.size();

        X = ' ' + X;
        Y = ' ' + Y;

        int lcs[1010][1010] = {};

        lcs[0][0] = 0;

        for (int x = 1; x <= xlen; ++x) {
            for (int y = 1; y <= ylen; ++y) {

                if (X[x] == Y[y]) {
                    lcs[x][y] = lcs[x - 1][y - 1] + 1;
                }
                else {
                    lcs[x][y] = max(lcs[x - 1][y], lcs[x][y - 1]);
                }
            }
        }

        cout << lcs[xlen][ylen] << endl;
    }
    
    return 0;
}