Go: package main

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

type Position struct {
	X int
	Y int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		strX := nextText(sc)
		strY := nextText(sc)
		fmt.Println(calcLcs(strX, strY))
	}
}

func calcLcs(strX, strY string) int {
	return lcs(strX, strY, Position{0, 0}, make(map[Position]int))
}

func lcs(strX string, strY string, position Position, memo map[Position]int) int {
	if position.X >= len(strX) || position.Y >= len(strY) {
		return 0
	}
	if v, ok := memo[position]; ok {
		return v
	}
	if strX[position.X] == strY[position.Y] {
		result := lcs(strX, strY, Position{position.X + 1, position.Y + 1}, memo)
		memo[position] = result + 1
		return memo[position]
	} else {
		result1 := lcs(strX, strY, Position{position.X + 1, position.Y}, memo)
		result2 := lcs(strX, strY, Position{position.X, position.Y + 1}, memo)
		var result int
		if result1 > result2 {
			result = result1
		} else {
			result = result2
		}
		memo[position] = result
		return result
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

func nextText(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define NIL -1
using namespace std;

int count(const string& X, int i, const string Y, int j,
          vector<vector<int> >& MEMO){
    if (i >= X.size() || j >= Y.size()) return 0;
    if (MEMO[i][j] != NIL) return MEMO[i][j];
    int next_X = count(X, i + 1, Y, j, MEMO);
    int j_next = Y.find(X[i], j);
    if (j_next == string::npos) return MEMO[i][j] = next_X;
    int saiyou = count(X, i + 1, Y, j_next + 1, MEMO) + 1;
    return MEMO[i][j] = max(saiyou, next_X);
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        string X, Y;
        cin >> X >> Y;
        vector<vector<int> > MEMO(X.size(), vector<int>(Y.size(), NIL));
        cout << count(X, 0, Y, 0, MEMO) << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main()
{
    int q;
    cin>>q;
    vector<int>ansvec(q);
    int count=0;
    while (count<q)
    {string x,y;
     cin >> x>>y;
     vector<vector<int>>dp(x.size()+1,vector<int>(y.size()+1));
     rep(i,x.size())
     {
         rep(j,y.size())
         {
             dp[i+1][j+1]= (x[i]==y[j]) ? dp[i][j]+1 : max(dp[i+1][j],dp[i][j+1]) ;
         }
     }
     ansvec[count]=dp[x.size()][y.size()];
     count++;
    }
    
    rep(i,q)
    {
        cout<<ansvec[i]<<endl;
    }
   
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i < n; ++i)

int max(int a, int b) {
  return a > b ? a : b;
}

int main(void) {
  int n;
  scanf("%d", &n);
  rep(i, n) {
    char x[1500], y[1500], h, w;
    scanf("%s", x);
    scanf("%s", y);
    h = strlen(x), w = strlen(y);
    int dp[h][w], len[w];
    rep(j, h) rep(k, w) dp[j][k] = 0;
    rep(j, w) if(x[0] == y[j]) dp[0][j] = 1;
    len[0] = 0;
    repi(j, w) len[j] = max(dp[0][j - 1], len[j - 1]);
    repi(j, h) {
      rep(k, w) if(x[j] == y[k]) dp[j][k] = len[k] + 1;
      repi(k, w) len[k] = max(dp[j][k - 1], max(len[k], len[k - 1]));
      /*rep(k, w) printf("%d ", len[k]);
      printf("\n");*/
    }
    /*printf("\n");
    rep(j, h) {
      rep(k, w) printf("%d ", dp[j][k]);
      printf("\n");
    }*/
    int maxs = 0;
    rep(j, w) if(maxs < dp[h - 1][j]) maxs = dp[h - 1][j];
    printf("%d\n", maxs);
  }
  return 0;
}

C++: #include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
bool isSubstring(string substr, string t) {
	int n = substr.length();
	int seek = 0;
	rep(i, n) {
		bool ex = 0;
		for (int j = seek; j < t.length(); j++) {
			if (substr[i] == t[j]) {
				ex = 1;
				seek = j + 1;
				break;
			}
		}
		if (ex) {
			continue;
		}
		else {
			return false;
		}
	}
	return true;

}

int LongestCommonSubstring(string s, string t) {
	vector<int>dp(s.length(), 0);
	int n = s.length();
	string lcs = "";
	if (isSubstring(s.substr(n - 1, n), t)) {

		dp[n - 1] = 1;
		lcs = s[n - 1];
	}
	for (int i = n - 2; i >= 0; i--) {
		//string substr = s.substr(i, n);
		string substr = s[i] + lcs;
		int issubst = isSubstring(substr, t);
		if (issubst) lcs = substr;
		dp[i] = dp[i + 1] + issubst;
	}
	return dp[0];
}
int main() {
	//cout << isSubstring("abc", "abcde") << endl;
	//cout << isSubstring("bd", "abcde") << endl;
	//cout << isSubstring("db", "abcde") << endl;

	//cout << LongestCommonSubstring("bacd", "becd") << endl;
	//cout << LongestCommonSubstring("abcd", "becd") << endl;
	int q;
	cin >> q;
	vector<string> s(q);
	vector<string> t(q);
	rep(i, q) {
		cin >> s[i] >> t[i];
	}
	rep(i, q) {
		cout << LongestCommonSubstring(s[i], t[i]) << endl;
	}

	return 0;
}

C++: #include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int dp[1024][1024];

int GetLengthOfLongestCommonSunseq(std::string &a, std::string &b) {
  int max = 0;
  for(int y = 0; y < a.size(); y++){
    for(int x = 0; x < b.size(); x++){
      const int vL = (y > 0) ? dp[y-1][x] : 0;
      const int vU = (x > 0) ? dp[y][x-1] : 0;
      const int vUL = (x > 0 && y > 0) ? dp[y-1][x-1] : 0;
      dp[y][x] = std::max(vL, std::max(vU, vUL + (a[y] == b[x] ? 1 : 0)));
      if(max < dp[y][x]) max = dp[y][x];
    }
  }
  return max;
}

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  for(int i = 0; i < n; i++){
    std::string a, b;
    std::cin >> a >> b;
    std::cout << GetLengthOfLongestCommonSunseq(a, b) << std::endl;
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

string s, t;

int main() {
	int n;
	cin >> n;
	while (n--) {
		//dp[i][j] := s???i??????????????§???t???j??????????????§?????£?????¨??????LCS
		vector<vector<int>> dp(200, vector<int>(200));
		cin >> s >> t;
		dp[0][0] = (s[0] == t[0]);
		for (int i = 1; i < s.size(); i++)dp[i][0] = (s[i] == t[0] || dp[i - 1][0]);
		for (int j = 1; j < t.size(); j++)dp[0][j] = (s[0] == t[j] || dp[0][j - 1]);
		
		for (int i = 1; i < s.size(); i++) {
			for (int j = 1; j < t.size(); j++) {
				if (s[i] == t[j])dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])+1;
				else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
		cout << dp[s.size() - 1][t.size() - 1] << endl;
	}
}