Go: package main

import "fmt"

func initialize_grid(width int,height int)[][]int{
	var grid [][]int
	for i:=0;i<height+1;i++{
		var grid_row  []int
		for j:=0;j<width+1;j++{
			grid_row = append(grid_row,0)
		}
		grid = append(grid,grid_row[:])
	}
	return grid
}

func ma(x int,y int)int{
	if x >= y{
		return x
	}else{
		return y
	}
}

func main()  {
	//Take input
	var num int
	var st1,st2 string
	var string_pairs [][]string
	fmt.Scan(&num)
	for i:=0;i<num;i++{
		var string_pair []string
		fmt.Scan(&st1)
		fmt.Scan(&st2)
		string_pair = append(string_pair,st1,st2)
		string_pairs = append(string_pairs,string_pair)
	}
	//DP
	//initialize grid
	for i:=0;i<num;i++{
		string_1 := string_pairs[i][0]
		string_2 := string_pairs[i][1]

		dp := initialize_grid(len(string_2),len(string_1))

		for j:=1;j<len(string_1)+1;j++{
			for k:=1;k<len(string_2)+1;k++{
				if string_1[j-1] == string_2[k-1]{
					dp[j][k] = dp[j-1][k-1] + 1
				}else{
					dp[j][k] = ma(dp[j-1][k],dp[j][k-1])
				}
			}
		}
		fmt.Println(dp[len(string_1)][len(string_2)])
	}
}

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;
}