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<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

void commonSeq(){
    string seq1, seq2;
    cin >> seq1;
    cin >> seq2;
    int nrow = seq1.length() + 1;
    int ncol = seq2.length() + 1;
    vector< vector<int> > dpmat;
    dpmat = vector< vector<int> >(nrow, vector<int>(ncol, 0));
    for(int i = 0; i < nrow; i++){
        dpmat[i][0] = 0;
    }
    for(int j = 0; j < ncol; j++){
        dpmat[0][j] = 0;
    }

    for(int i = 1; i < nrow; i++){
        for(int j = 1; j < ncol; j++){
            dpmat[i][j] = max(max(dpmat[i-1][j-1] + (seq1[i-1] == seq2[j-1]), dpmat[i-1][j]), dpmat[i][j-1]);
        }
    }
    printf("%d\n", dpmat[nrow-1][ncol-1]);
}

int main(){
    int n; 
    cin >> n;
    for(int i = 0; i < n; i++){
        commonSeq();
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999

#define MAX_S 2000
#define MAX_T 2000

template<typename T> int lcs(T s,T t){
    int lens=s.size();
    int lent=t.size();
    int dp[MAX_S+1][MAX_T+1]={};

    rep(i,lens){
        rep(j,lent){
            if(s[i]==t[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]);
        }
    }
    return dp[lens][lent];
}

int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s,t;
        cin>>s>>t;
        cout<<lcs(s,t)<<endl;
    }
}

C++: #include<iostream>
#include<array>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int MAX_V = 1001;
array<array<int, MAX_V>,MAX_V> ary;
string strx,stry;
int minimum(int x,int y){
  int res=strx[x-1]==stry[y-1]?ary[x-1][y-1]+1:ary[x-1][y-1];
  if(res<ary[x][y-1]) res=ary[x][y-1];
  if(res<ary[x-1][y]) res=ary[x-1][y];
  return res;
}

int main(){
  int n; cin>>n;
  REP(i,n){
    cin>>strx>>stry;
    int sizex=strx.size(),sizey=stry.size();
    REP(j,sizex)
      REP(k,sizey)
        ary[j+1][k+1]=minimum(j+1,k+1);
    cout<<ary[strx.size()][stry.size()]<<endl;
  }
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j])
	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];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

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

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

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

  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
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 = 0; 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;
  }
}

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

using namespace std;
int LCS(const char* a,const char* b)
{
    int m=strlen(a); int n=strlen(b); //i???????¬????a????????????j???????¬????b?????????
    int c[m+1][n+1]; //c??°???????????¨?????°???????¬????a??????i??????????¬????b??????j????????´???LCS
    for(int i=0;i<=m;i++) c[i][0]=0;
    for(int i=0;i<=n;i++) c[0][i]=0;
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++)
        {
            if(a[i]==b[j]) c[i+1][j+1]=c[i][j]+1;
            else
            {
                c[i+1][j+1]=max(c[i][j+1],c[i+1][j]);
            }
        }
    return c[m][n];

}
int main()
{
    char *a=new char[1001];
    char *b=new char[1001];
    int q;
    while(cin>>q)
    {
        for(int i=0;i<q;i++)
        {
            cin>>a>>b;
            cout<<LCS(a,b)<<endl;
        }
    }
}

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