Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <list>
#include <stack>

typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int MAX = 20*200+1;

int LCS(string S, string T);

int main() {

    int n; cin >> n;
    vector<int> ans(n);
    for (int i = 0; i < n; i++) {
        string s, t;
        cin >> s >> t;
        ans[i] = LCS(s, t);
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << '\n';
    }

}

int LCS(string S, string T) {

    int row = S.size();
    int column = T.size();
    vector< vector<int> > dp(row, vector<int>(column, 0));

    for (int i = 0; i < row; i++) {
        if(S[i] == T[0]) {
            dp[i][0] = 1;
        }
        if (i > 0) {
            if (dp[i-1][0])
                dp[i][0] = 1;
        }
    }
    for (int i = 0; i < column; i++) {
        if(S[0] == T[i]) {
            dp[0][i] = 1;
        }
        if (i > 0) {
            if (dp[0][i-1])
                dp[0][i] = 1;
        }
    }

    for (int i = 1; i < row; i++) {
        for (int j = 1; j < column; 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]);
            }
        }
    }

    return dp[row-1][column-1];

}

C++: #include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#define MAX 100000


int lcs(std::string X, std::string Y) {
    int c[MAX][MAX];
    int maxl = 0;
    int m = X.size();
    int n = Y.size();
    for (int i = 1; i <= m; i++) {
        c[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) {
        c[0][i] = 0;
    }
    X = ' ' + X;
    Y = ' ' + Y;
    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] = std::max(c[i-1][j], c[i][j-1]);
            }
            maxl = std::max(maxl, c[i][j]);
        }
    }
    return maxl;
}

int main() {
    std::string s1, s2;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        std::cin >> s1 >> s2;
        int a = lcs(s1, s2);
        printf("%d\n", lcs(s1, s2));
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int q;
    cin >> q;
    rep(i, q) {
        string x, y;
        cin >> x >> y;
        vi l;
        rep(k, sz(y)) {
            int xbi = 0;
            bool skip = false;
            rep(j, sz(l)) {
                int p = x.find(y[k], xbi);
                if (p == (int)string::npos) {
                    skip = true;
                    break;
                }
                xbi = l[j];
                l[j] = min(l[j], p+1);
            }
            if (!skip) {
                int p = x.find(y[k], xbi);
                if (p != (int)string::npos) l.pb(p+1);
            }
        }
        cout << sz(l) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int dp[1001][1001];
string x,y;

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

  for ( int i = 1; i <= m; i++){
    for ( int l = 1; l <= n; l++){
      if(x[i] == y[l]){
        dp[i][l] = dp[i-1][l-1] + 1;
      } else {
        dp[i][l] = max(dp[i][l-1], dp[i-1][l]);
      }
    }
  }
  return dp[m][n];
}

int main(){
  int q;
  cin >> q;
  // init
  for ( int i = 0 ; i < q; i++){

    string X, Y;
    cin >> X >> Y;
    x = ' ' + X;
    y = ' ' + Y;

    cout << calc_dp(X.length(), Y.length()) << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
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 ;
}