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<bits/stdc++.h>
using namespace std;
int main(){
  int cnt;
  cin>>cnt;
  while(cnt--){
    string a,b;
    cin>>a>>b;
    int dp[1000][1000]={};
    for(int i=0;i<b.size();i++){
      int nm=0;
      for(int j=0;j<a.size();j++){
	if(a[j]==b[i])dp[i][j]=nm+1;
	if(i){
	  dp[i][j]=max(dp[i][j],dp[i-1][j]);
	  nm=max(nm,dp[i-1][j]);
	}
      }
    }
    int ans=0;
    for(int i=0;i<a.size();i++)ans=max(ans,dp[b.size()-1][i]);
    cout<<ans<<endl;
   
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 1002;
const ll M = 21;
ll q,dp[N][N];
string x,y;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>q;
	FOR(k,0,q){
		cin>>x>>y;
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				dp[i][j]=0;
			}
		}
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				if(i==0||j==0)dp[i][j]=0;
				else{
					if(x[i]==y[j])dp[i][j] = max(dp[i-1][j]+1,dp[i][j-1]+1);
					else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				} 
			}
		}
		cout<<dp[x.size()][y.size()]<<endl;
	}
	return 0;
}

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

#define MAX 1000

int lcs(string X, string Y){
    int c[MAX + 1][MAX + 1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for(int i = 0; i <= m; i++) c[i][0] = 0;
    for(int i = 1; i <= n; i++) c[0][i] = 0;
    cout << "test" << endl;
    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;
}

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

int lcs(string x, string y) {
  int dp[1001][1001];
  int maxl=0;
  x = ' ' + x;
  y = ' ' + y;
  for (int i = 0; i < x.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 0; i < y.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 1; i < x.size(); i++)
  {
    for (int j = 1; j < y.size(); j++)
    {
      if (x[i] == y[j]) {
        dp[i][j] = dp[i-1][j-1] + 1;
      }
      else {
        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
      }
    maxl = max(maxl, dp[i][j]);
    }
    
  }
  return maxl;
}

int main(){

  //std::ifstream in ("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string a, b;
    cin >> a >> b;
    cout << lcs(a, b) << endl;
  }
  return 0;
  
}

C++: #include<iostream>
#include<vector>
#include<limits.h>
#include<string>
using namespace std;

int LCS(string a, string b){
	int n=a.size();
	int m=b.size();
	int T[n+1][m+1];
	int i,j;
	for (i=0;i<n+1;i++) T[i][0]=i;
	for (j=0;j<m+1;j++) T[0][j]=j;
	for (i=1;i<n+1;i++){
		for (j=1;j<m+1;j++){
			int min=T[i-1][j]+1;
			if (min>T[i][j-1]+1){
				min=T[i][j-1]+1;
			}
			if ((a[i-1]==b[j-1])&&(min>T[i-1][j-1]+1)){
				min=T[i-1][j-1]+1;
			}
			T[i][j]=min;
		}
	}
	return n+m-T[n][m];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,i;
	cin >> n;
	
	string a,b;
	for (i=0;i<n;i++){
		cin >> a >> b;
		cout << LCS(a,b) << endl;
	}
	return 0;
}

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

void solve(){
    string S, T;
    cin >> S;
    cin >> T;

    int dp[1001][1001];
    dp[0][0] = 0;

    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] = dp[i][j] + 1;
            else
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }
    cout << dp[S.size()][T.size()] << endl;
}

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

    for (int i = 0; i < q; i++)
        solve();
}