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] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// 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++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp




#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

const int MAX_q=160;
const int MAX_L=1010;
bool done[MAX_L][MAX_L];
int memo[MAX_L][MAX_L];
int q;
string x,y;

int LCS(int i,int j)
{
    int res;

    if(i<0) return 0;
    if(j<0) return 0;

    if (done[i][j]) return memo[i][j];

    else if(x[i]==y[j])
    {
        res=LCS(i-1,j-1)+1;
    }
    else{
        int res1=LCS(i-1,j);
        int res2=LCS(i,j-1);
        res=max(res1,res2);
    }
    done[i][j]=true;
    memo[i][j]=res;
    return res;
}

int main()
{
    int res;
    cin>>q;
    rep(i,q)
    {
        cin>>x>>y;
        res=LCS(x.length()-1,y.length()-1);
        cout<<res<<"\n";
        rep(j,MAX_L)
        {
            rep(k,MAX_L)
            {
                done[j][k]=false;
            }
        }
    }


    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int L[1001][1001];
int getc(int i,int j){
    if(i>=0&&j>=0)
        return L[i][j];
    else
        return 0;
}
int main(){
    int N;
    string X,Y;
    cin >> N;
    for(int k=0;k<N;++k){
        cin>>X>>Y;
        for(int i=0;i<X.length();++i){
            for(int j=0;j<Y.length();++j){
                if(X[i]==Y[j]){
                    L[i][j]=getc(i-1,j-1)+1;
                }
                else{
                    L[i][j]=max(getc(i-1,j),getc(i,j-1));
                }
            }
        }
        cout <<L[X.length()-1][Y.length()-1]<< endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

const int MAX_N = 1333;

int dp[MAX_N][MAX_N];

int LCS(string &s, string &t) {
    int n=s.length(); int m=t.length();
    if (!n||!m) return 0;
    memset(dp,-1,sizeof(dp));
    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) {
            if (s[i-1]==t[j-1]) dp[i][j]=max({dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1]});
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    return dp[n][m];
}

int main(int argc, char const *argv[]) {
    int q;cin>>q;
    rep(i,q) {
        string s,t;
        cin>>s>>t;
        cout << LCS(s,t) << endl;
    }
    return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int N;
  cin>>N;
  string S1,S2;
  for (int k=0; k<N; k++) {
    cin>>S1>>S2;
    int m=S1.length();
    int n=S2.length();
    S1=' '+S1;
    S2=' '+S2;
    int lcs[m+1][n+1];
    for (int i=1; i<=m; i++) {
      lcs[i][0]=0;
    }
    for (int j=1; j<=n; j++) {
      lcs[0][j]=0;
    }
    int maxl=0;
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (S1[i]==S2[j]) {
          lcs[i][j]=lcs[i-1][j-1]+1;
        }
        else {
          lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
        maxl=max(maxl,lcs[i][j]);
      }
    }
    cout<<maxl<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#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]);
			}
		}
	}
	return C[m][n];
}

int main(int argc, char *argv[]) {
	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;

static const int N = 1000;

int lcs(string X,string Y){
    int c[N+1][N+1];    //c[i][k]???Xi??¨Yk???LCS??¨??????????????????
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X; // X[0]?????????????????\
    Y = ' ' + Y;
    for(int i=1;i<=m;i++) c[i][0] = 0;
    for(int k=1;k<=n;k++) c[0][k] = 0;

    for(int i=1;i<=m;i++){
        for(int k=1;k<=n;k++){
            if(X[i]==Y[k]){
                c[i][k] = c[i-1][k-1] + 1;
            } else {
                c[i][k] = max(c[i-1][k],c[i][k-1]);
            }
            maxl = max(maxl,c[i][k]);
        }
    }

    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;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

UL dp[1001][1001];

void Case(){
 string S,T; cin>>S>>T;
 rep(i,S.size()+1) rep(j,T.size()+1) dp[i][j]=0;
 rep(i,S.size()) rep(j,T.size()){
  dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
  if(S[i]==T[j]) dp[i+1][j+1]=dp[i][j]+1;
 }
 cout<<dp[S.size()][T.size()]<<endl;
}

int main() {
 UL T; cin>>T;
 rep(t,T) Case();
 return 0;
}