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 <bits/stdc++.h>

#define MOD 1000000007
#define INF (1<<30)
#define INFL (1<<62)
#define pe(str) return cout<<(str)<<endl,0
#define px(str) cout<<(str)<<endl,exit(0)
#define accu(ac,v) cout<<setprecision(ac)<<v<<endl
#define bpc(a) __builtin_popcount(a)
#define pr(str) cout<<(str)<<endl
#define prpr(str) cout<<str<<endl
#define db(str) cerr<<"debug:"<<(str)<<endl
#define dbdb(str) cerr<<"debugs:"<<str<<endl
#define re(i,n) for(int i=0;i<(n);i++)
#define rre(i,n) for(int i=(n);i>=0;i--)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b);i>=(a);i--)
#define bw(a,b,c) (((a)<=(b))&&((b)<=(c)))
#define hello cout<<"hello"<<endl
#define spre(a) setprecision(a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define s3(C,T,F) ((C)?(T):(F))
#define max3(a,b,c) max((a),max((b),(c)))
#define min3(a,b,c) min((a),min((b),(c)))
#define max4(a,b,c,d) max((a),max((b),max((c),(d))))
#define min4(a,b,c,d) min((a),min((b),min((c),(d))))
#define enl cout<<endl
#define declare(t,n) t n;cin>>n

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef complex<int> point;

template<class InputIterator>
void dump(InputIterator first,InputIterator last,char delim=' '){
	for(InputIterator it=first;it!=last;it++){
		if(it!=first)cout<<delim;
		cout<<*it;
	}
}

ull p(ull x,ull y){
	if(y==0) return 1;
	ull A=p(x,y/2)%MOD;
	return (y&1?((A*A)%MOD*x)%MOD: (A*A)%MOD);
	// return (y&1?((A*A)*x):(A*A));
}

template<class T>
void swp(T &a,T &b){
	T t=a; a=b; b=t;
}

int main(void){
	int dp[100][100];
	string a,b;
	int n;
	cin>>n;

	while (n--) {
		cin>>a>>b;
		re(i,a.size()) re(j,b.size()) dp[i][j]=0;
		rep(i,1,a.size()+1){
			rep(j,1,b.size()+1){
				dp[i][j]=max(dp[i-1][j-1]+(a[i-1]==b[j-1]),dp[i-1][j]);
				dp[i][j]=max(dp[i][j],dp[i][j-1]);
			}
		}
		cout<<dp[a.size()][b.size()]<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != '\0')
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw = 0){
    if(B[b] != '\0')
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1 i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[j-1])
        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];
      if(max < C[i][j])
        max = c[i][j];
    }
  }
  
  return max;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", a);
    scanf("%s", b);
    printf("%d\n", judge(a, b));
  }
  
  return 0;
}

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

int main()
{
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	for (int i = 1; i <= n; i++) m[i][i] = 0;

	for (int l = 2; l <= n; l++)
	{
		for (int i = 1; i <= n; i++)
		{
			int j = i + l - 1;
			m[i][j] = 1 << 21;
			for (int k = i; k <= j - 1; k++)
			{
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] * p[i - 1] * p[k] * p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

void lcs(string s, string t){
    int m = s.size() + 1;
    int n = t.size() + 1;
    vector<vector<int>> dp(m, vector<int>(n));
    rep(i, m) dp[i][0] = 0;
    rep(i, n) dp[0][i] = 0;
    for (int i = 1; i < m; i++){
        for (int j = 1; j < n; j++){
            if (s[i - 1] == t[j - 1])
                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];
        }
    }
    cout << dp[m - 1][n - 1] << endl;
}

int main(){
    int q;
    cin >> q;
    string s, t;
    rep(k, q) {
        cin >> s >> t;
        lcs(s, t);
    }
    return 0;
}

C++: #include <iostream>
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() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n;
  cin>>n;
  string s1,s2;
  for (int i=0; i<n; i++) {
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
  int k,m,n,i,j,q,c[1001][1001],max=0;
  char X[1000],Y[1000];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s %s",X,Y);
    m=strlen(X);
    n=strlen(Y);
    for(j=m;j>=1;j--){
      X[j]=X[j-1];
    }
    X[0]=' ';
    X[m+1]='\0';
    for(j=n;j>=1;j--){
      Y[j]=Y[j-1];
    }
    Y[0]=' ';
    Y[n+1]='\0';
    for(j=1;j<=m;j++)c[j][0]=0;
    for(j=1;j<=n;j++)c[0][j]=0;
    for(j=1;j<=m;j++){
      for(k=1;k<=n;k++){
	if(X[j]==Y[k])c[j][k]=c[j-1][k-1]+1;
	else{
	  if(c[j][k-1]>c[j-1][k])c[j][k]=c[j][k-1];
	  else c[j][k]=c[j-1][k];
	}
	if(max<c[j][k])max=c[j][k];
      }
    }
    printf("%d\n",max);
    max=0;
  }
  return 0;
}