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 f() {
	var S, T string
	fmt.Scan(&S)
	fmt.Scan(&T)
	lenS, lenT := len(S), len(T)
	dp := make([][]int, lenS+1)
	for i:=0; i<lenS+1; i++ {
		dp[i] = make([]int, lenT+1)
	}
	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])
}

func main(){
	var n int 
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		f()
	}
}

C++: #pragma region Macros
#include <bits/stdc++.h>

#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()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(_, n) {
    string a, b;
    cin >> a >> b;
    vector<vector<int>> dp(a.size() + 1, vector<int>(b.size() + 1, 0));
    REP(i, a.size()) {
      REP(j, b.size()) {
        if (a[i] == b[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        }
        chmax(dp[i + 1][j + 1], dp[i][j + 1]);
        chmax(dp[i + 1][j + 1], dp[i + 1][j]);
      }
    }
    cout << dp[a.size()][b.size()] << endl;
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int q;

string x, y;

int dp(string x, string y){
  int longest[1051][1051];
  for(int j = 1; j <= y.size(); ++j){
    for(int i = 1; i <= x.size(); ++i){
      if(i <= 0 || j <= 0){
        longest[i][j] = 0;
      }else if(x[i - 1] == y[j - 1]){
        longest[i][j] = 1 + longest[i-1][j-1];
      }else{
        longest[i][j] = max(longest[i][j -1], longest[i - 1][j]);
      }
    }
  }
  //cout << x.size() << endl;
  return longest[x.size()][y.size()];
}

int main(){
  cin >> q;
  while(q != 0){
    q--;
    cin >> x;
    cin >> y;
    
    cout << dp(x, y) << endl;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
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=0;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)<<'\n';
    }
    return 0;
}

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

typedef long long ll;
#define inf 1e9+7

int dp[1001][1001];
char x[1001],y[1001];

void init(){
    for(int i=0;i<1001;i++){
        dp[0][i]=0;
        dp[i][0]=0;
    }
}

void solve(int sn, int tn){
    for(int i=1;i<=sn;i++){
        for(int j=1;j<=tn;j++){
            if(x[i-1]==y[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s,t;
    for(int i=0;i<n;i++){
        init();
        cin >> s >> t;
        int sn=s.size();
        int tn=t.size();
        for(int j=0;j<sn;j++){
            x[j]=s[j];
        }
        for(int j=0;j<tn;j++){
            y[j]=t[j];
        }

        solve(sn, tn);
        cout << dp[sn][tn] << endl;
    }

}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define INFTY (1<<30)
#define MAX 100000000

using namespace std;

int lcs(string x, string y) {
	int m = x.size(), n = y.size();
	int c[1000+1][1000+1];
	x = ' ' + x; y = ' ' + y;
	for( int i = 0; i <= m; i++) c[i][0] = 0;
	for( int j = 0; j <= n; j++) c[0][j] = 0;
	for( int i = 1; i <= m; i++) {
		for( int j = 0; j <= n; j++) {
			if(x[i] == y[j]) c[i][j] = c[i-1][j-1];
			else if(c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j];
			else c[i][j] = c[i][j-1];
		}
	}
	return c[m][n];
}

int main(){
	int q;
	cin >> q;
	for( int i = 0; i < q; i++) {
		string s, t;
		cin >> s >> t;
		cout << lcs(s, t) <<endl;
	}

	return 0;
}

C++: //============================================================================
// Name        : LongestCommonSeq.cpp
// Author      : Ken
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

class DPMatrix{
public:
	vector<vector<int> > matrix;
	string seq1;
	string seq2;

	DPMatrix(const string sequence1, const string sequence2):matrix(),seq1(sequence1), seq2(sequence2){
		for(int i=0; i<sequence1.size()+1; i++){
			vector<int> vec(sequence2.size()+1);
			matrix.push_back(vec);
		}
	}

	void update(int i, int j){
		if(i<1 or j<1){
			cout << "caution! i: " << i << ", j: " << j << "\n";
		}

		if(seq1.at(i-1) == seq2.at(j-1)){
			matrix.at(i).at(j) = max(matrix.at(i).at(j-1), max(matrix.at(i-1).at(j), matrix.at(i-1).at(j-1)+1));
		}else{
			matrix.at(i).at(j) = max(matrix.at(i).at(j-1), max(matrix.at(i-1).at(j), matrix.at(i-1).at(j-1)));
		}
	}

	int fillMatrix(){
		for(int i=1; i<seq1.size()+1; i++){
			for(int j=1; j<seq2.size()+1; j++){
				update(i, j);
			}
		}

		return matrix.at(seq1.size()).at(seq2.size());
	}
};

int main() {
	int n;
	string sequence1, sequence2;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> sequence1;
		cin >> sequence2;

		DPMatrix dpmat(sequence1, sequence2);
		int score = dpmat.fillMatrix();

		cout << score << "\n";
	}

	return 0;
}