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 <cstring>
using namespace std;
#define len_max 1000


string X;
string Y;
int dp[len_max+1][len_max+1];

int lcs(){
    int m = X.length();
    int n = Y.length();

    X = ' ' + X;//ずらす
    Y = ' ' + Y;
    

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

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

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

}


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

    int ans[q];

    for(int i = 0; i < q; i++){
        cin >> X >> Y;
        //printf("%d\n", lcs());
        ans[i] = lcs();
    }

    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXL = 1e3+7;
char s1[MAXL];
char s2[MAXL];
int dp[MAXL][MAXL];
int maxLCS(char s1[], char s2[]){
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    int i;
    for(i = 0; i <= l1; i++){
        dp[0][i] = 0;
    }
    for(i = 0; i <= l2; i++){
        dp[i][0] = 0;
    }
    int j;
    for(i = 1; i <= l2; i++){
        for(j = 1; j <= l1; j++){
            int max_k = max(dp[i-1][j], dp[i][j-1]);
            if(s1[j-1] == s2[i-1]) max_k = max(max_k, dp[i-1][j-1]+1);
            else max_k = max(max_k, dp[i-1][j-1]);
            dp[i][j]= max_k;
        }
    }
    return dp[l2][l1];
}
int main(){
//    freopen(".../in.txt", "r", stdin);
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s", s1);
        scanf("%s", s2);
        int q = maxLCS(s1, s2);
        printf("%d\n", q);
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>

#define MAX_LENGTH 1000
#define NIL -1
using namespace std;
//think easy make easy

int q;//num of datasets
string X;
string Y;
char map[MAX_LENGTH+1][MAX_LENGTH+1];

int findMaxLength(int x,int y){//x:Xの終端.y:Yの終端(0オリジン)
	int val;

	if(x < 0 || y < 0) return 0;

	if(map[x][y] == NIL){
		if(X.at(x) == Y.at(y)){
			val = findMaxLength(x-1,y-1) +1;
		}else{
			val = max(findMaxLength(x-1,y),findMaxLength(x,y-1));
		}
		map[x][y] = val;//メモ
		return val;
	}else return map[x][y];
}

int main(){
	
	scanf("%d",&q);

	for(int i=0;i<q;i++){
		cin >>X; cin >> Y;
		for(int i=0;i<X.size();i++){
			for(int j=0;j<Y.size();j++){
				map[i][j] = NIL;
			}
		}
	
		cout <<findMaxLength(X.size()-1,Y.size()-1) <<endl;
	}

	return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;
int dp[1001][1001];
int lcs(string x,string y){
  int m,n;
  lll ii,jj,kk;
  
  m = x.size();
  n = y.size();
  memset(dp,0,sizeof(dp));
  int maxl = 0;

  for(ii=0;ii<m;ii++){
    for(jj=0;jj<n;jj++){
      if(x[ii] == y[jj]){
        dp[ii+1][jj+1] = dp[ii][jj] + 1;
      }
      else{
        dp[ii+1][jj+1] = max(dp[ii][jj+1],dp[ii+1][jj]);
      }

      maxl = max(maxl,dp[ii+1][jj+1]);
      
    }
  }
  return maxl;
}

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int q;
  string x,y;

  cin >> q;

  for(ii=0;ii<q;ii++){
    cin >> x >> y;
    cout << lcs(x,y) << endl;
  }

  return 0;
}

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

static const int N = 100;

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 - l + 1; 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 <string>
using namespace std;

int preX[1020][55];
int dp[1020];

int main() {
	int q;
	cin >> q;
	for(int t = 0; t < q; t++) {
		string X, Y;
		for(int i = 0; i < 1020; i++) {
			for(int j = 0; j < 55; j++) {
				preX[i][j] = 0;
			}
			dp[i] = 0;
		}
		cin >> X >> Y;
		for(int i = 0; i < X.size(); i++) {
			for(int j = 0; j < 55; j++) {
				preX[i+1][j] = preX[i][j];
			}
			if(i > 0) {
				if('a' <= X[i-1] && X[i-1] <= 'z')
					preX[i+1][X[i-1]-'a'] = i;
				else
					preX[i+1][X[i-1]-'A'] = i;
			}
		}
		for(int i = 0; i < Y.size(); i++) {
			for(int j = (int)X.size()-1; j >= 0; j--) {
				if(Y[i] == X[j])
					for(int k = 0; k < 55; k++)
						dp[j+1] = max(dp[j+1], dp[preX[j+1][k]] + 1);
			}
		}
		int res = 0;
		for(int i = 0; i < 1020; i++)
			res = max(res, dp[i]);
		cout << res << endl;
	}
}

C++: //compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int solve(string x, string y){
	int xl = x.length() - 1;
	int yl = y.length() - 1;
	int dp[1250][1250];
		for(int i=0;i<=xl;i++) dp[i][0] = 0;
		for(int i=1;i<=yl;i++) dp[0][i] = 0;
	if(x == y) return max(xl, yl);
	for(int i=1;i<=xl;i++){
		for(int j=1;j<=yl;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]);
		}
	}
	return dp[xl][yl];
}

int main(){
	int q;
	string x, y;
	int i;
	cin >> q;
	rep(i, q){
		cin >> x >> y;
		cout << solve(x = " " + x, y = " " + y) <<endl;
	}


}