Go: package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

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

using namespace std;

string s[2];
int q;
int dp[1000][1000];

int solve(int x,int y) {
	if(x == -1 || y == -1) return 0;
	if(dp[x][y] == -1) {
		if(s[0][x] == s[1][y]) dp[x][y] = solve(x-1,y-1) + 1;
		else dp[x][y] = max(solve(x-1,y),solve(x,y-1));
	}
	return dp[x][y];
}

int main() {
	cin >> q;
	for(int i = 0;i < q;i++) {
		for(int i = 0;i < 1000;i++)for(int j = 0;j < 1000;j++)dp[i][j] = -1;
		cin >> s[0] >> s[1];
		cout << solve(s[0].size()-1,s[1].size()-1) << endl;
	}
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;

int lcs(string s1, string s2)
{
	int m = len(s1);
	int n = len(s2);
	s1 = ' '+s1;
	s2 = ' '+s2;
	int (*mat)[1001];
	mat = new int[1001][1001];
	REP(i, m)
	{
		mat[i][0] = 0;
	}
	REP(i, n)
	{
		mat[0][i] = 0;
	}
	int maxx = 0;
	FOR(i, 1, m+1)
	{
		FOR(j, 1, n+1)
		{
			if (s1[i] == s2[j])
				mat[i][j] = mat[i-1][j-1] + 1;
			else
				mat[i][j] = max(mat[i][j-1], mat[i-1][j]);
			maxx = max(maxx, mat[i][j]);
		}
	}
	delete[] mat;
	return maxx;
}
int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	REP(i, n)
	{
		string s1;
		cin >> s1;
		string s2;
		cin >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define LENGTH 1000

using namespace std;

int LCSLength(string X, string Y){
    int m = X.size();
    int n = Y.size();
    int c[LENGTH+1][LENGTH+1];
    int maxLength = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for(int i = 1; i <= m; i++) c[i][0] = 0;
    for(int j = 0; 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 if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
            else c[i][j] = c[i][j-1];
            maxLength = max(maxLength, c[i][j]);
        }
    }
    return maxLength;
}

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

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int N = 1000;

int C[N + 1][N + 1];

int lcs(string X, string Y)
{
    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(int argc, char const *argv[])
{
    string s1, s2;
    int n; 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        int ans = lcs(s1, s2);
        cout << ans << endl;
    }    

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#define rep(i,n) for(int i = 0;i < n;i++)
#define N 20005
using namespace std;
int main(){
    int Testcase;
    cin >> Testcase;
    while(Testcase--){
        string s1,s2;
        cin>>s1>>s2;
        int l1=s1.length(),l2=s2.length();
        int dp[1005][1005];
        rep(i,l1+1){
            rep(j,l2+1){
                dp[i][j]=0;
            }
        }
        rep(i,l1){
            rep(j,l2){
                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]);
                }
            }
        }
        cout << dp[l1][l2]<<endl;
    }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    int m = x.size();
    int n = y.size();
    int maxl=0;
    for (int i=1; i<=m; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=n;j++){
        c[0][j] = 0;
    }
    x = ' '+x;
    y = ' '+y;
    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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<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;
  C[0][0] = 0;
  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]);
    }
  }javascript:void(0)

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