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

int main(){
  int n;
  cin>>n;
  string str1,str2;
  vector<int> ans(n);
  cin.ignore();
  for(int i=0; i<n; i++){
    vector<char> a;
    vector<char> b;
    getline(cin,str1);
    for(int j=0; j<(int)str1.size(); j++){
      char ch=str1[j];
      a.push_back(ch);
    }
    getline(cin,str2);
    for(int j=0; j<(int)str2.size(); j++){
      char ch=str2[j];
      b.push_back(ch);
    }
  	int path[a.size()+1][b.size()+1];
  	for(int h=0; h<a.size()+1; h++){
  		for(int w=0; w<b.size()+1; w++){
  			if(h==0 || w==0){
  				path[h][w]=0;
  			}else{
  				int max=path[h-1][w];
  				if(max<path[h][w-1]) max=path[h][w-1];
  				if(a[h-1]==b[w-1] && max<path[h-1][w-1]+1){
  					max=path[h-1][w-1]+1;
  				}
  				path[h][w]=max;
  			}
  		}
  	}
  	ans[i]=path[a.size()][b.size()];
  }
  for(int i=0; i<n; i++){
  	cout<<ans[i]<<endl;
  }
  return 0;
}

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

int lcs(string X, string Y) {
  int cs[1001][1001];
  int m = X.size();
  int n = Y.size();
  int answer = 0;
  X = ' ' + X;
  Y = ' ' + Y;
  for (int i = 1; i <= m; i++) cs[i][0] = 0;
  for (int j = 1; j <= n; j++) cs[0][j] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        cs[i][j] = cs[i - 1][j - 1] + 1;
      } else {
        cs[i][j] = max(cs[i - 1][j], cs[i][j - 1]);
      }
      answer = max(answer, cs[i][j]);
    }
  }

  return answer;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  string X, Y;

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

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin >> n;
    rep(i,n){
        string a,b;
        cin >> a >> b;
        int n1 = a.size();
        int n2 = b.size();
        int dp[n1+1][n2+1];
        rep(i,n1+1)rep(j,n2+1)dp[i][j] = 0;
        rep(i,n1)rep(j,n2){
            if(a[i+1] == b[j+1])dp[i+1][j+1] = min(dp[i+1][j],dp[i][j+1])+1;
            else dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
        cout << dp[n1][n2] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#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 FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second
int dp[1100][1100]; 

int main() {
	int n;
	string a, b;
	cin >> n;
	REP(z, n) {
		cin >> a >> b;
		REP(i, 1100) REP(j, 1100) dp[i][j] = 0;
		REP(i, a.length()) {
			REP(j, b.length()) {
				if (a[i] == b[j]) dp[i + 1][j + 1] = max(dp[i][j] + 1, max(dp[i][j + 1], dp[i + 1][j]));
				else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
		cout << dp[a.length()][b.length()] << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<algoritm>
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(){
  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 <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;//??¨X[0]????????\?????????
	Y=' '+Y;//??¨Y[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]);
		}
	}
	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<vector>
#include<string>

using namespace std;

class Dataset{
private:
 string X;
 string Y;
public:
 Dataset(){
  string tmp = "";
  cin >> tmp; X = tmp; X = " " + X;
  cin >> tmp; Y = tmp; Y = " " + Y;
 };

 unsigned long getLongestCommonLength(){
  unsigned long Xsize = X.size();
  unsigned long Ysize = Y.size();
 
  vector< vector<unsigned long> > LC(Xsize, vector<unsigned long>(Ysize, 0));

  for(unsigned long X_i = 1; X_i < Xsize; ++X_i){
   for(unsigned long Y_i = 1; Y_i < Ysize; ++Y_i){
    unsigned long tmp = LC[X_i][Y_i-1];
    if(X[X_i] == Y[Y_i]) ++tmp;
    if(tmp < LC[X_i-1][Y_i]) tmp = LC[X_i-1][Y_i];
    LC[X_i][Y_i] = tmp;
   }
  }

  return LC[Xsize-1][Ysize-1];
 };


protected:
};

int main(){
 long datasetNum = 0; cin >> datasetNum;
 for(unsigned long dataset_i = 0; dataset_i < datasetNum; ++dataset_i){
  Dataset data;
  cout << data.getLongestCommonLength() << endl;
 }

 return 0;
};