Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	for i := 0; i < num; i++ {
		sc.Scan()
		in1 := sc.Text()
		sc.Scan()
		in2 := sc.Text()
		countMax(in1, in2)
	}
}

func countMax(in1 string, in2 string) {
	counta := make([][]int, len(in2)+1)
	for i := 0; i < len(in2)+1; i++ {
		for j := 0; j < len(in1)+1; j++ {
			counta[i] = append(counta[i], 0)
		}
	}

	// fmt.Println(counta)
	for a1, v1 := range in1 {
		i1 := a1 + 1
		for a2, v2 := range in2 {
			i2 := a2 + 1
			// fmt.Printf("1:%v 2:%v\n", i1, i2)
			if v1 == v2 {
				counta[i2][i1] = counta[i2-1][i1-1] + 1
				continue
			}
			val := counta[i2-1][i1]
			if val < counta[i2][i1-1] {
				val = counta[i2][i1-1]
			}

			counta[i2][i1] = val
		}
	}
	fmt.Println(counta[len(in2)][len(in1)])
}

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

static int lc[1000][1000];
static std::string X, Y;

int count(int idx_x, int idx_y) {
    if (lc[idx_x][idx_y] != -1) {
        return lc[idx_x][idx_y];
    }

    int maximum = 0;
    
    if (X[idx_x] == Y[idx_y]) {
        if (idx_x > 0 && idx_y > 0) {
            maximum = std::max(maximum, count(idx_x - 1, idx_y - 1));
        }
        lc[idx_x][idx_y] = maximum + 1;
    } else {
        if (idx_x > 0) {
            maximum = std::max(maximum, count(idx_x - 1, idx_y));
        }
        if (idx_y > 0) {
            maximum = std::max(maximum, count(idx_x, idx_y - 1));
        }
        lc[idx_x][idx_y] = maximum;
    }
    return lc[idx_x][idx_y];
}

int LongestCommon() {
    for (int i = 0; i < X.length(); i++) {
        for (int j = 0; j < Y.length(); j++) {
            lc[i][j] = -1;
        }
    }
    return count(X.length() - 1, Y.length() - 1);
}

int main() {
    int q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        std::cin >> X >> Y;
        std::cout << LongestCommon() << std::endl;
    }
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, al, bl;
  string k, l;
  int ans[1001][1001];
  cin >> N;

  rep(i, N){
    cin >> k;
    cin >> l;

    al = k.length();
    bl = l.length();


    rep(j, al+1){
      rep(s, bl+1){
        ans[j][s] = 0;
      }
    }

    rep(j, al){
      rep(s, bl){
        if(k[j] == l[s]){
          ans[j+1][s+1] = max(ans[j+1][s], max(ans[j][s+1], ans[j][s] + 1));
        } else{
          ans[j+1][s+1] = max(ans[j+1][s], ans[j][s+1]);
        }
      }
    }

    cout << ans[al][bl] << "\n";



  }
}

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

int dp[1001][1001];
int main() {
	int b;
	scanf("%d", &b);
	char e[1001];
	char f[1001];
	for (int c = 0; c < b; c++) {
		scanf("%s%s", e, f);
		for (int g = 0; g <= strlen(e); g++) {
			for (int h = 0; h <= strlen(f); h++) {
				dp[g][h] = 0;
			}
		}
		for (int g = 1; g <= strlen(e); g++) {
			for (int h = 1; h <= strlen(f); h++) {
				if (e[g] == f[h]) {
					dp[g][h] = dp[g - 1][h - 1] + 1;
				}
				else {
					dp[g][h] = max(dp[g][h - 1], dp[g - 1][h]);
				}
			}
		}
		printf("%d\n", dp[strlen(e)][strlen(f)]);
	}
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int q;
string x, y;
int dp[1111][1111];

void solve() {
   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-1][j], dp[i][j-1]);
         }
      }
   }
   cout << dp[x.size()][y.size()] << endl;
}

int main() {
   cin >> q;
   while (q--) {
      fill(dp[0], dp[1111], 0);
      cin >> x >> y;
      solve();
   }

   return 0;
}

C++: #include<iostream>
#include<vector>b
using namespace std;
int main()
{
	int kurikaeshi;
	vector<int> answer;
	cin >> kurikaeshi;
	for (int variable = 0;variable < kurikaeshi;++variable) {
		char X[1024], Y[1024];
		int LX = 0, LY = 0;
		vector<vector<int>> L;
		cin >> X >> Y;
		for (int i = 0;X[i] != 0;++i) LX += 1;
		for (int j = 0;Y[j] != 0;++j) LY += 1;
		L.resize(LX+1);
		for (int k = 0;k < LX + 1;++k) L[k].resize(LY+1);
		for (int i = 0;X[i] != 0;++i) {
			for (int j = 0;Y[j] != 0;++j) {
				if (i == 0 || j == 0) {
					L[i][j] = 0;
				}
				else if (X[i] == Y[j]) {
					L[i+1][j+1] = L[i+1][j] + 1;
				}
				else {
					L[i+1][j+1] = L[i][j+1] > L[i+1][j] ? L[i][j+1] : L[i+1][j];
				}
			}
		}
		answer.push_back(L[LX][LY]+1);
	}
	for (int variable = 0;variable < kurikaeshi;++variable) {
		cout << answer[variable] << endl;
	}
}

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

using namespace std;

int results[1001][1001];

int lcs(string x, string y)
{
    // initialize
    for (int i = 0; i < 1001; ++i) {
        for (int j = 0; j < 1001; ++j)
            results[i][j] = 0;
    }

    int maxlcs = 0;
    for (int i = 1; i <= x.length(); ++i) {
        for (int j = 1; j <= y.length(); ++j) {
            if (x[i-1] == y[j-1])
                results[i][j] = results[i-1][j-1] + 1;
            else
                results[i][j] = max(results[i-1][j], results[i][j-1]);

            if (maxlcs < results[i][j])
                maxlcs = results[i][j];
        }
    }
    return maxlcs;
}

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

    vector<string> x(n);
    vector<string> y(n);
    for (int i = 0; i < n; ++i)
        cin >> x[i] >> y[i];

    for (int i = 0; i < n; ++i)
        cout << lcs(x[i], y[i]) << '\n';
}

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

int main() {
    int q;
    cin >> q;
    
    rep(i,q) {
        string X,Y;
        cin >> X >> Y;
        int lX=X.size(), lY=Y.size();
        vector<vector<int>> dp(lX+1, vector<int>(lY+1,0));

        rep(i,lX)
            rep(j,lY)
                if(X.at(i) == Y.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(lX).at(lY) << endl;
    }
}