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 <string>
using namespace std;

int lcs(string X, string Y) {
	int dp[1000 + 1][1000 + 1];
	int max = 0;

	for (int i = 0; i < X.length(); i++)
		dp[i][0] = 0;

	for (int i = 0; i < Y.length(); i++)
		dp[0][i] = 0;

	for (int i = 1; i < X.length(); i++) {
		for (int j = 1; j < Y.length(); j++) {
			if (X[i] == Y[i])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else if (dp[i - 1][j] >= dp[i][j - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = dp[i][j - 1];
			max = (max < dp[i][j]) ? dp[i][j] : max;
		}
	}

	return max;
}

int main() {
	int N;
	cin >> N;

	for (int i = 0; i < N; i++) {
		string X, Y;
		cin >> X >> Y;

		cout << lcs(X, Y) << endl;
	}

  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
string a,b;
int la,lb;
int dp[10000][10000];

void dpf(void){
	for(int i=1;i<=la;i++){
		for(int j=1;j<=lb;j++){
			if(a[i]==b[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}	
	return ;
}
int n;

int main(void){
	cin>>n;
	
	
for(int i=0;i<n;i++){	
	cin>>a>>b;
	la=a.length();
	lb=b.length();
	a=' '+a;
	b=' '+b;
	dpf();
	cout<<dp[la][lb]<<endl;
}


}

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

int main() {
  std::string X;
  std::string Y;
  int q;
  int answers[160];
  std::cin >> q;
  
  for(int p=0; p<q; ++p) {
    std::cin >> X;
    std::cin >> Y;

    int j=0;
    int c=0;

    for(int i=0; i<X.size(); ++i) {
      for(int k=j; k<=i; ++k) {
        if(k >= Y.size()) {
          break;
        }
        if(X[i] == Y[k]) {
          c++;
          j = k+1;
          break;
        }
      }
    }

    answers[p] = c;
  }

  for(int i=0; i<q; ++i) {
    std::cout << answers[i] << std::endl;
  }

}

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

int lcs(string x,string y);

int main(){
	int n; cin>>n;
	string x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		cout<<lcs(x,y)<<endl;
	}
}

int lcs(string x,string y){
	int m = x.size() , n = y.size();
	x = ' '+x; y = ' '+y;
	int **c;
	c = new int*[m+1]; for(int i=0;i<=m;i++) c[i] = new int[n+1];
	for(int i=0;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
				c[i][j] = max(c[i-1][j],c[i][j-1]);
			if(i==m&&j==n) return c[i][j];
		}
	}

	for(int i=0;i<=m;i++) delete [] c[i]; delete [] c;
}

C++: #include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

const int kMax = 1000 + 10;

int n, m;
char a_str[kMax], b_str[kMax];
int dp[kMax];

vector<int> init_num() {
    vector<int> res;
    map<char, set<int> > table;
    for(int i = 0;i < n;++ i) {
        if(table.count(a_str[i]) > 0) table[a_str[i]].insert(i);
        else {
            set<int> s;
            s.insert(i);
            table[a_str[i]] = s;
        }
    }
    for(int i = 0;i < m;++ i) {
        if(table.count(b_str[i]) > 0) {
            for(auto it = table[b_str[i]].rbegin();it != table[b_str[i]].rend();++ it) {
                res.push_back(*it);
            }
        }
    }
    return res;
}

int solve() {
    int res = 1;
    n = strlen(a_str);
    m = strlen(b_str);
    vector<int> num = init_num();
    dp[0] = num[0];
    for(int i = 1;i < num.size();++ i) {
        if(dp[res - 1] < num[i]) dp[res ++] = num[i];
        else dp[lower_bound(dp, dp + res, num[i]) - dp] = num[i];
    }
    return res;
}

int main() {
    int q;
    scanf("%d", &q);
    while(q --) {
        scanf("%s%s", a_str, b_str);
        printf("%d\n", solve());
    }
    return 0;
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int dp[1000][1001] = {0};

void dfs(int i, int j, string q, string b){
    int x = j;
    string tar = b.substr(x, 1);
    while(x < b.length() && q != tar){
        x++;
        tar = b.substr(x, 1);
    }
    if(i == 0 && x < b.length()){
        while(x < b.length()){
            x++;
            dp[i][x] = 1;
        }
        return;
    }
    while(x < b.length()){
        x++;
        dp[i][x] = max(dp[i-1][j] + 1, dp[i][x]);
    }
    dp[i][j] = max(dp[i][j], dp[i-1][j]);
    return;
}

int main() {
    int n; cin >> n;
    REP(k, n){
        string a, b;
        cin >> a >> b;
        REP(i, a.length()){
            string q = a.substr(i, 1);
            REP(j, b.length()+1) dfs(i, j, q, b);
        }
        cout << dp[a.length()-1][b.length()] << endl;
    }
    return 0;
}