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] = 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 <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
const int MAX_Q = 150, MAX_X = 1000;
int q, dp[MAX_X + 1][MAX_X + 1];
string x[MAX_X], y[MAX_X];

void solve() {
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < x[i].length(); j++) {
            for (int k = 0; k < y[i].length(); k++) {
                if (x[i][j] == y[i][k]) {
                    dp[j + 1][k + 1] = dp[j][k] + 1;
                } else {
                    dp[j + 1][k + 1] = max(dp[j][k + 1], dp[j + 1][k]);
                }
            }
        }
        cout << dp[x[i].length()][y[i].length()] << endl;
    }
}

int main() {
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> x[i] >> y[i];
    }
    solve();
    return 0;
}

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

C++: //Longest Common Subsequence
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int q;
  string X, Y;
  int dp[1001][1001]={};
  int m, n;
  int ans;


  cin >> q;
  REP(s, q){
    dp[1001][1001]={};
    cin >> X >> Y;
    m=X.size();
    n=Y.size();
    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][j+1], dp[i+1][j]);
      }
    }
    cout << dp[m][n] <<endl;
  }


  return 0;
}

C++: #include<iostream>
using namespace std;
int lcs(string a,string b)
{
    if(a.length()<=0||b.length()<=0)
    {
        return 0;
    }
    else if(a[a.length()-1]==b[b.length()-1])
    {
        return 1+lcs(a.substr(0,a.length()-1),b.substr(0,b.length()-1));
    }
    else
    {
        return max(lcs(a.substr(0,a.length()),b.substr(0,b.length()-1)),lcs(a.substr(0,a.length()-1),b.substr(0,b.length())));
    }
};
int main()
{
    int num;
    cin>>num;
    for(int i=0;i<num;i++)
    {
        string a,b;
        cin>>a>>b;
        cout<<lcs(a,b)<<endl;
    }
}

C++: #include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    *t++;
    while(t != V.end()) {
        cout << " " << *t++;
        // if(t != V.end()) cout << " ";
    }
    cout << endl;
};
vector<vector<int>> dp(1001, vector<int>(1001));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    string S, T;
    cin >> Q;
    rep(q, Q) {
        cin >> S >> T;
        dp.assign(S.size() + 1, vector<int>(T.size() + 1, 0));
        rep(i, 0, S.size()) {
            rep(j, 0, T.size()) {
                if(S.at(i) == T.at(j)) {
                    dp.at(i + 1).at(j + 1) = dp.at(i).at(j) + 1;
                } else {
                    dp.at(i + 1).at(j + 1) =
                        max(dp.at(i + 1).at(j), dp.at(i).at(j + 1));
                }
            }
        }
        cout << dp.at(S.size()).at(T.size()) << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#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(), 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(){
    ios::sync_with_stdio(false);
    string s1, s2;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> s1 >> s2;
      cout << lcs(s1, s2) << endl;
    }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
int dp[1000+1][1000+1];
int lim;
//int cost_vec[/*num*/];
//int val_vec[/*num*/];
int main() {
	int num;
	cin >> num;
	vector<string> vec(2*num);
	REP(i, num) {
		cin >> vec[2 * i];
		cin >> vec[2 * i + 1];
	}
	REP(i, num) {
		memset(dp, 0, sizeof(dp));
		REP(k, vec[i * 2].size()) {
			REP(n, vec[i * 2+1].size()) {
				if (vec[i * 2][k] == vec[i * 2 + 1][n]) {
					dp[k + 1][n + 1] = dp[k][n] + 1;
				}
				else {
					dp[k + 1][n + 1] = max(dp[k][n + 1], dp[k + 1][n]);
				}
			}
		}
		cout << dp[vec[i * 2].size()][vec[i * 2+1].size()] << endl;
	}
	return 0;
}