Go: package main

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

func max(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

/*********************************************************************
長さmの列X_(m)と長さnの列Y_(n)の最長共通部分列LCSは、
	(1)X[m] == Y[n]ならば、X_(m-1)とY_(n-1)のLCSにX[m]を繋げたもの
	(2)X[m] != Y[n]ならば、X_(m-1)とY_(n)のLCSもしくはX_(m)とY_(n-1)のLCS
	のいずれかのうち長い方

c[m+1][n+1]：c[i][j]にX_(i)とY_(j)のLCSの長さを格納する二次元配列
*********************************************************************/

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

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

int LCS(string X, string Y) {
  /*
  if (X.length() == 0 || Y.length() == 0) {
    return 0;
  }
  else if (X[X.length()-1] == Y[Y.length()-1]) {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return LCS(miniX, miniY) + 1;
  }
  else {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return max(LCS(miniX, Y), LCS(X, miniY));
  }
  */
 int m = X.length(), n = Y.length();
 int c[m+1][n+1];
 for (int i = 0; i <= m; i++) {c[i][0] = 0;}
 for (int i = 0; i <= n; i++) {c[0][i] = 0;}
 int maxL = 0;
 X = ' '+ X; Y = ' ' + Y;
 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][j-1], c[i-1][j]);
  maxL = max(maxL, c[i][j]);   
  }
 }
 return maxL;
}
int main(void) {
  int q; cin >> q;
  string X[q], Y[q];
  for (int i = 0; i < q; i++)  {
    cin >> X[i] >> Y[i];
  }

  int ans[q];
  for (int i = 0; i < q; i++) {
    ans[i] = LCS(X[i], Y[i]);
  }

  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX_SEQ 1000

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

  for(int i=0;i<n;i++) {
    int subseq_len = 0;
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;

    for(int seq1_it=0;seq1[seq1_it]!='\0';seq1_it++) {
      vector<char>::iterator it = find(seq_sub.begin(), seq_sub.end(), seq1[seq1_it]);
        if (it == seq_sub.end()) {
          seq_sub.push_back(seq1[seq1_it]);
        }
    }
    for(int seq2_it=0;seq2[seq2_it]!='\0';seq2_it++) {
      vector<char>::iterator it = find(seq_sub.begin(), seq_sub.end(), seq2[seq2_it]);
        if (it != seq_sub.end()) {
          seq_sub.erase(it);
          subseq_len++;
        }
    }
    cout << subseq_len << endl;
  }
}

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++: #include <bits/stdc++.h>
using namespace std;

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

	for( int i = 0; i < q; i++ ) {
		string X, Y;
		cin >> X >> Y;
		int m = X.size();
		int n = Y.size();
		vector<vector<int>> c( m + 1, vector<int>( n + 1 ) );
		for( int j = 1; j < m + 1; j++ ) {
			for( int k = 1; k < n + 1; k++ ) {
				if( X[j - 1] == Y[k - 1] ) {
					c[j][k] = c[j - 1][k - 1] + 1;
				}
				else {
					c[j][k] = max( c[j][k - 1], c[j - 1][k] );
				}
			}
		}
		cout << c[m][n] << endl;
	}
}

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

int main() {
  uint32_t q = 0;
  std::cin >> q;
  while (q > 0) {
    q--;
    std::string X, Y;
    std::cin >> X >> Y;

    std::vector<std::vector<uint32_t>> dp(
        X.size() + 1, std::vector<uint32_t>(Y.size() + 1, 0));
    for (size_t i = 1; i < X.size() + 1; i++) {
      for (size_t j = 1; j < Y.size() + 1; j++) {
        dp[i][j] =
            (X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1
                                  : std::max(dp[i][j - 1], dp[i - 1][j]));
      }
    }

    std::cout << dp.back().back() << std::endl;
  }

  return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

int dat[1024][1024];
int getLcbLen(char* x, int xe, char* y, int ye){
	if(xe <= 0 || ye <= 0) return 0;
	if(dat[xe][ye] != -1) return dat[xe][ye];
	return dat[xe][ye] = (x[xe-1] == y[ye-1] ? 1 + getLcbLen(x, xe-1, y, ye-1) : max(getLcbLen(x, xe-1, y, ye), getLcbLen(x, xe, y, ye-1)));
}

int main() {
	int set;
	scanf("%d", &set);
	
	while(set--){
		char x[1024], y[1024];
		scanf("%s %s", x, y);
		
		for(int i = 0; i < 1024; i++){
			for(int k = 0; k < 1024; k++){
				dat[i][k] = -1;
			}
		}
		printf("%d\n", getLcbLen(x, (int)strlen(x), y, (int)strlen(y)));
	}
	return 0;
}