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 <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int q;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> q;
  rep(qi,q) {
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.size();
    vector<vector<int>> dp(n+10, vector<int>(m+10, 0));
    rep(i,n) rep(j,m) {
      if(x[i] == y[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
      else {
        chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
      }
    }
    cout << dp[n][m] << '\n';
  }
  return 0;
}

C++: #include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<vin> vvin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
const int MOD=1e9+7;

int main(){
  ll u;cin>>u;
  rep(k,0,u){

  string x,y;cin>>x>>y;
  ll n=x.size(),m=y.size();
  vvll dp(n+1,vll(m+1,0));
  
  rep(i,0,n){
    rep(j,0,m){
      if(x[i]==y[j])dp[i+1][j+1]=max(dp[i][j]+1,max(dp[i][j+1],dp[i+1][j]));
      else{dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);}
    }
  }
  
  cout<<dp[n][m]<<endl;
  }
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int c[1010][1010];
int lcs(string x,string y){
    int m = x.size();
    int n = y.size();
    int maxl;
    for (int i=1; i<=m; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=n;j++){
        c[0][j] = 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] = max(c[i-1][j], c[i][j-1]);
            maxl = max(maxl, c[i][j]);
        }
        
    }
    return maxl;
}
int main(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

void commonSeq(){
    string seq1, seq2;
    cin >> seq1;
    cin >> seq2;
    int nrow = seq1.length() + 1;
    int ncol = seq2.length() + 1;
    vector< vector<int> > dpmat;
    dpmat = vector< vector<int> >(nrow, vector<int>(ncol, 0));
    for(int i = 0; i < nrow; i++){
        dpmat[i][0] = 0;
    }
    for(int j = 0; j < ncol; j++){
        dpmat[0][j] = 0;
    }

    for(int i = 1; i < nrow; i++){
        for(int j = 1; j < ncol; j++){
            dpmat[i][j] = max(max(dpmat[i-1][j-1] + (seq1[i-1] == seq2[j-1]), dpmat[i-1][j]), dpmat[i][j-1]);
        }
    }
    printf("%d\n", dpmat[nrow-1][ncol-1]);
}

int main(){
    int n; 
    cin >> n;
    for(int i = 0; i < n; i++){
        commonSeq();
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999

#define MAX_S 2000
#define MAX_T 2000

template<typename T> int lcs(T s,T t){
    int lens=s.size();
    int lent=t.size();
    int dp[MAX_S+1][MAX_T+1]={};

    rep(i,lens){
        rep(j,lent){
            if(s[i]==t[j])  dp[i+1][j+1] = dp[i][j]+1;
            else            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }
    return dp[lens][lent];
}

int main(){
    int n;
    cin>>n;
    rep(i,n){
        string s,t;
        cin>>s>>t;
        cout<<lcs(s,t)<<endl;
    }
}

C++: #include<iostream>
#include<array>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
const int MAX_V = 1001;
array<array<int, MAX_V>,MAX_V> ary;
string strx,stry;
int minimum(int x,int y){
  int res=strx[x-1]==stry[y-1]?ary[x-1][y-1]+1:ary[x-1][y-1];
  if(res<ary[x][y-1]) res=ary[x][y-1];
  if(res<ary[x-1][y]) res=ary[x-1][y];
  return res;
}

int main(){
  int n; cin>>n;
  REP(i,n){
    cin>>strx>>stry;
    int sizex=strx.size(),sizey=stry.size();
    REP(j,sizex)
      REP(k,sizey)
        ary[j+1][k+1]=minimum(j+1,k+1);
    cout<<ary[strx.size()][stry.size()]<<endl;
  }
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

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

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

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

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

  string X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  }

  return 0;
}