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 FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

    auto solve = [](const string& s, const string& t) {
        const int n = s.length(), m = t.length();
        string s1 = " " + s, t1 = " " + t;

        auto dp = make_v(n + 1, m + 1, 0);
        
        FOR(i, 1, n + 1)FOR(j, 1, m + 1) {
            if (s1[i] == t1[j]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j -  1] + 1);
            }
            dp[i][j] = max(dp[i][j], dp[i][j - 1]);
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }

        return dp[n][m];
    };

    REP(i, n) {
        string s, t; cin >> s >> t;

        cout << solve(s, t) << endl;
    }

    return 0;
}

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

using namespace std;
static const int N = 150;
static const int AX = 1000, AY = 1000;
string  X, Y;

int do_dp(int ax,int ay) {

    int dp[AX][AY];



    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;
    int q;

    cin >> q;

    int A[N];

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

string LCS(string s, string t){
    ll ns = s.size();
    ll nt = t.size();
    vector< vector<ll> > dp(ns+1, vector<ll> (nt+1, 0));
    // initilaize
    rep(i, 0, ns){
        if(s[i] == t[0]) dp[i][0] = 1;
    }
    rep(i, 0, nt){
        if(s[0] == t[i]) dp[0][i] = 1;
    }
    // build DP table
    rep(i, 1, ns){
        rep(j, 1, nt){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
        }
    }
    // make LCS
    string ret;
    ll i = ns-1, j = nt-1;
    while(i >= 0 && j >= 0){
        if(s[i] == t[j]){
            ret.push_back(s[i]);
            i--; j--;
        }else{
            if(j == 0) i--;
            else if(i == 0) j--;
            else if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    return ret;
}

int main(){
    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        string x, y;
        cin >> x >> y;
        cout << LCS(x, y).size() << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <memory>
#include <string>
#include <map>
using namespace std;
#define MAX 1003

char A[MAX];
char B[MAX];

void print(){}
int DP[MAX][MAX];
int dp(int i,int j){
    if(i==0||j==0) return 0;
    if(DP[i][j]!=-1) return DP[i][j];
    if(A[i]==B[j]) return DP[i][j]=dp(i-1,j-1)+1;
    return DP[i][j]=max(dp(i,j-1),dp(i-1,j));
}
void solve(){
    memset(DP,-1,sizeof(DP));

    int tmp;
        scanf("%d",&tmp);
        while(tmp--){
                memset(DP,-1,sizeof(DP));
                scanf("%s%s",A,B);
            printf("%d\n",dp(strlen(A),strlen(B)));
        }

}

int main(){

  //  freopen("in","r",stdin);
    solve();
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
 
#define N 1000
 
char A[N+1],B[N+1];
  

  
int Max(int a,int b){
  if(a>=b) return a;
  else return b;
}
int main(){
  int k,a,i,j,m,n,max,c[N+1][N+1];
  scanf("%d",&a);
  for(k=0;k<a;k++){
    scanf("%s",A);
    scanf("%s",B);
    max=0;
     m=strlen(A);
  n=strlen(B);
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0][j]=0;
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;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];
      max=Max(max,c[i][j]);
    }
  }
    printf("%d\n",max);
  }
  
  return 0;
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 1000;
char s[N+1], t[N+1];
int ls, lt;
int q;
int dp[N+1][N+1];
//dp[i][j] = s[0]...s[i+1]??¨t[0]...t[j+1]???LCS
//(1<=i<=ls, 1<=j<=lt)

int main() {
  int i, j, k;
  scanf("%d ", &q);
  for (k=0; k<q; k++) {
    ls = lt = 0;
    memset(s, 0, sizeof(s)), scanf("%s ", s);
    memset(t, 0, sizeof(t)), scanf("%s ", t);
    while (s[ls]) ls++;
    while (t[lt]) lt++;

    memset(dp, 0, sizeof(dp));
    for (i=1; i<=ls; i++)
      for (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]);
      }

    printf("%d\n", dp[ls][lt]);
  }

  return 0;
}