Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
	"sort"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// if S[i-1] == T[j-1] {
				// 	dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				// } else {
				// 	dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				// }
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
	int m = strlen(s1), n = strlen(s2);
	for (int i = 1; i <= m; i++)
		c[i][0] = 0;
	for (int i = 1; i <= n; i++)
		c[0][i] = 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
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
		}
	}
	return c[m][n];
}
int main()
{
	char s1[maxx], s2[maxx];
	int t;
	scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		cin >> s1 >> s2;
		printf("%d\n", lcs(s1,s2));
	}

	return 0;
}

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


int S[1001][1001];

void prep(string str1, string str2, int len)
{
	int a, b, i;
	S[0][0] = 0;
	for(i = 1; i <= len; i++){ S[0][i] = 0;  S[i][0] = 0; }
	for(a = 1; a <= len; a++){
		for(b = 1; b <= len; b++){
			if(str1[a - 1] == str2[b - 1]){ S[a][b] = 1; }else{ S[a][b] = 0; }
		}
	}
	return;
}

int main()
{
	int i, a, b, q, len;
	cin >> q;
	string str1, str2;

	for(i = 0; i < q; i++){
		cin >> str1 >> str2;
		len = str1.size();

		prep(str1, str2, len);

		for(a = 1; a <= len; a++){
			for(b = 1; b <= a; b++){
				if(S[b][a + 1 - b]){
					S[b][a + 1 - b] = S[b - 1][a - b] + 1; 
				}else{
					S[b][a + 1 - b] = max(S[b - 1][a + 1 - b], S[b][a - b]); }
			}
		}
		for(a = 2; a <= len; a++){
			for(b = a; b <= len; b++){
				if(S[b][len + a - b]){
					S[b][len + a - b] = S[b - 1][len + a - b - 1] + 1; 
				}else{
					S[b][len + a - b] = max(S[b - 1][len + a - b], S[b][len + a - b - 1]); }
			}
		}
		cout << S[len][len] << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 100000000
const int MOD = 1000000009;

//マクロ
#define FOR(i, a, b) for(int i = (a); i < (b), i++)
#define REP(i, n) FOR(i, 0, n);
#define ALL(a) (a).begin(),(a).end()

// 最長共通部分列問題
// 入力
// S T

// dp[i + 1][j + 1] := Sのi文字目までと、Tのj文字目までのLCSの長さ
// 計算量 O(|S||T|)

int main(){

    //入力
    int n; cin >> n;
    for(int roop = 0; roop < n; roop++){
        string S, T; cin >> S >> T;
        vector<vector<int> > dp(S.size() + 1, vector<int> (T.size() + 1, 0));

        //dp初期条件
        dp[0][0] = 0;

        //dp
        for(int i = 0; i < S.size(); i++){
            for(int j = 0; j < T.size(); j++){
                if(S[i] == T[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            }
        }

        cout << dp[S.size()][T.size()] << endl;
        
    }

    return 0;
}

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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

//    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

C++: #include <cstdint>
#include <string>
#include <utility>

using namespace std;

#define MAX_LEN 1001
static size_t memo[MAX_LEN][MAX_LEN];

size_t lcs(string &a, string &b)
{
  for (uint32_t i = 0; i <= a.size(); i++) {
    memo[i][0] = 0;
  }

  for (uint32_t i = 0; i <= b.size(); i++) {
    memo[0][i] = 0;
  }

  for (uint32_t i = 1; i <= a.size(); i++) {
    for (uint32_t j = 1; j <= b.size(); j++) {
      if (a[i - 1] == b[j - 1]) {
        memo[i][j] = memo[i - 1][j - 1] + 1;
      } else {
        memo[i][j] = max(memo[i - 1][j], memo[i][j - 1]);
      }
    }
  }

  return memo[a.size()][b.size()];
}

#include <iostream>

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    string a, b;
    cin >> a;
    cin >> b;
    cout << lcs(a, b) << endl;
  }

  return 0;
}