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>
#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 <= m; j++ ) c[0][j] = 0;

  for ( int i = 1; i <= m; i++ )
    for ( int j = 1; j <= m; 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 <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

int LCS(string &s, string &t){
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n+8, vector<int>(m+8, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(s[i]==t[j]){
                dp[i+1][j+1] = max({dp[i][j]+1, dp[i][j+1], dp[i+1][j]});
            }
            else{
                dp[i+1][j+1] = max({dp[i][j], dp[i][j+1], dp[i+1][j]});
            }
        }
    }
    return dp[n][m];
}
signed main(){
    int q;
    cin >> q;
    for(long long i=0; i<q; i++){
        string s, t; cin>>s>>t;
        cout << LCS(s, t) << endl;
    }
    return 0;
}

C++: 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
int mod(ll a){
    int c=a%1000000007;
    if(c>=0)return c;
    else return c+1000000007;
}
typedef pair<int,int> i_i;


int main(){
    int q;cin>>q;
    while(q){
        char s[1005],t[1005];cin>>s>>t;
        ll ls=strlen(s),lt=strlen(t);
        for(ll i=ls-1;i>=0;i--)s[i+1]=s[i];
        for(ll j=lt-1;j>=0;j--)t[j+1]=t[j];
        int dp[ls+1][lt+1];
        for(int i=0;i<=ls;i++)dp[i][0]=0;
        for(int j=0;j<=lt;j++)dp[0][j]=0;
        for(int i=1;i<=ls;i++){
            for(int j=1;j<=lt;j++){
                if(s[i]==t[j])dp[i][j]=dp[i-1][j-1]+1;
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout<<dp[ls][lt]<<endl;
        q--;
    }
    
    return 0;
}

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

using namespace std;

int main() {
    
    int a = 0;
    
    cin >> a;
    
    string s1, s2;
    
    for(int k = 0; k < a; k ++) {
        
        cin >> s1 >> s2;
        
        int m = s1.size();
        
        int n = s2.size();
        
        int c[1005][1005] = {};
        
        int Amax = 0;
        
        s1 = ' ' + s1;
        
        s2 = ' ' + s2;
        
        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 (s1[i] == s2[j]) {
                    
                    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];
                    
                }
                
                Amax = max(Amax,c[i][j]);
                
            }
            
        }
        
        cout << Amax << endl;
        
    }
    
    return 0;
    
}

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

using namespace std;

string  X,Y;
int q;

int do_dp(int ax,int ay){
  int dp[ax + 100][ay + 100] = {0};
  
  for(int i = 0;i < ax;i++){
    if(X[i] == Y[0]) dp[i][0] = 1;
    if(i > 0) dp[i][0] = max(dp[i][0],dp[i - 1][0]);
  }
  
  for(int j = 0;j < ay;j++){
    if(X[0] == Y[j]) dp[0][j] = 1;
    if(j > 0) dp[0][j] = max(dp[0][j],dp[0][j - 1]);
  }

  for(int i = 1;i < ax;i++){
    for(int j = 1;j < ay;j++){
      if(X[i] == Y[j]){
	dp[i][j] = dp[i - 1][j - 1] + 1;
      }else{
	dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]);
      }
    }
  }
  
  /*for(int i = 0;i < ax;i++){
    for(int j = 0;j < ay;j++){
      cout << dp[i][j] << " ";
    }
    cout << '\n';
    }*/
  
  return dp[ax - 1][ay - 1];
}

int main(){
  string str;
  
  cin >> q;
  
  int A[q];
  
  for(int i = 0;i < q;i++){
    cin >> X;
    cin >> Y;
    //cout << X.size() << " " << Y.size() << '\n';
    A[i] = do_dp(X.size(),Y.size());
  }
  
  for(int i = 0;i < q;i++){
    cout << A[i] << '\n';
  }
  
  return 0;
}