Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}

C++: #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int main(){
  
  int n;
  cin>>n;
  
  int a,b;
  string x,y;
  while(n--){
    cin>>x>>y;
    a=x.size();
    b=y.size();
    int vec[a+1][b+1];
    rep(i,a+2) vec[i][0]=0;
    rep(i,b+2) vec[0][i]=0;
    for(int i=1;i<a+1;i++){
      for(int j=1;j<b+1;j++){
        if(x[i-1]==y[j-1]) vec[i][j]=vec[i-1][j-1]+1;
        else vec[i][j]=max(vec[i][j-1],vec[i-1][j]);
      }
    }
    cout<<vec[a][b]<<endl;
  }
      
  return 0;
}

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

using namespace std;

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

	int q;
	string X,Y;
	//unsigned char 
	int dp[99][99];
	
	dp[0][0] = 0; dp[0][1] = 0; dp[1][0] = 0;

	cin >> q;
	for(int k=0; k < q; k++){
		cin >> X >> Y;
		int i,j;
		for(i=0;i<X.size();i++){
			for(j=0;j<Y.size();j++){
				if(X[i] == Y[j]) dp[i+1][j+1] = dp[i][j] + 1;
				else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			}
		}
		cout << dp[i][j] << "\n";
	}
	return 0;
}

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 = 0; i <= m; i++) {
    c[i][0] = 0;
  }
  for (int j = 1; i < n; i++) {
    c[0][j] = 0;
  }

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[i]) {
        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 <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

#define REP(i,n) for(int i = 0;i < n;i++)

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;

int solve(void) {
  string x, y;
  cin >> x >> y;

  int xl = x.length(), yl = y.length();
  int dp[xl][yl];

  dp[0][0] = (int)(x[0] == y[0]);
  for (int j = 1;j < yl;j++)
    dp[0][j] = max(dp[0][j-1], (int)(x[0] == y[j]));
  for (int i = 1;i < xl;i++) {
    dp[i][0] = max(dp[i-1][0], (int)(x[i] == y[0]));
    for (int j = 1;j < yl;j++) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (x[i] == y[j]) {
	dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      }
    }
  }

  return dp[xl-1][yl-1];
}


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

  int cases;
  cin >> cases;
  REP(i, cases) {
    cout << solve() << "\n";
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 1010;
int c[maxx][maxx];

int lcs(char s1[],char s2[]) {
    int m = strlen(s1), n = strlen(s2);
    for (int i = 0; i <= m; i++)
    c[i][0] = 0;
    for (int i = 0; i <= n; i++)
    c[0][i] = 0;
    
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (s1[i] == s2[j])
            c[i+1][j+1] = c[i][j] + 1;
            else
            c[i+1][j+1] = max(c[i][j+1], c[i + 1][j]);
        }
    }
    return c[m][n];
}
int main()
{
    char s1[maxx], s2[maxx];
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        scanf("%s %s", s1, s2);
        printf("%d\n",lcs(s1,s2));
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define clr(a,v) memset((a),(v),sizeof(a))

int q;
int dp[1000][1000];
std::string s, t;

int rec( int i, int j )
{
  int &ret = dp[i][j];

  if( ~ret )
    return ret;

  if( i == s.size() || j == t.size() )
    return 0;

  ret = 0;

  if( s[i] == t[j] )
    ret = std::max( ret, rec( i+1, j+1 )+1 );

  ret = std::max( { ret, rec( i+1, j ), rec( i, j+1 ) } );

  return ret;
}

int main()
{
  scanf( "%d", &q );
  while( q-- )
  {
    std::cin >> s >> t;

    clr( dp, -1 );

    std::cout << rec( 0, 0 ) << std::endl;
  }

  return 0;
}

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

using namespace std;

string str1,str2;

int m[1000][1000];

int LCS(int i,int j){
  
  if(m[i][j]!=0){
    return m[i][j];
  }
  if(i==-1||j==-1){
    return 0;
  }else if(str1[i]==str2[j]){
    m[i][j]=LCS(i-1,j-1)+1;
    return m[i][j];
  }else{
    m[i][j]=max(LCS(i-1,j),LCS(i,j-1));
    return m[i][j];
  }
  
}

int main(){
  int N;
  
  cin >> N;
  
  
  for(int i=0;i<N;i++){
    cin >> str1 >> str2;
    for(int j=0;j<str1.size();j++){
      for(int k=0;k<str2.size();k++){
        m[j][k]=0;
      }
    }
    cout << LCS(str1.size()-1,str2.size()-1) << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxx=1010;

int main (){
	int dp[maxx][maxx];
	string s,p;
	int q;
	cin>>q;
	while(q--){
		cin>>s>>p;
		for(int i=0;i<=s.size();i++){
			for(int j=0;j<=p.size();j++){
				if(i==0||j==0) dp[i][j]=0;
				else if(s[i]==p[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[s.size()][p.size()]<<endl;
	}
	return 0;
}

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

using namespace std;

const int max_size = 1001;

int main() {
  int n_input; // number of inputs of pairs of sequences
  cin >> n_input;

  for (int i = 0; i < n_input; i++) {
    string seq1, seq2;
    cin >> seq1 >> seq2;
    int seq1_len = seq1.length(), seq2_len = seq2.length();
    int grid[max_size][max_size] = {{0}};
    for (int rowi = 1; rowi <= seq1_len; rowi++) {
      for (int coli = 1; coli <= seq2_len; coli++) {
	if (seq1[rowi - 1] == seq2[coli - 1]) {
	  grid[rowi][coli] = grid[rowi - 1][coli - 1] + 1;
	} else {
	  int above_grid = grid[rowi - 1][coli], left_grid = grid[rowi][coli - 1];
	  grid[rowi][coli] = (above_grid >= left_grid)?above_grid:left_grid;
	}
      }
    }
    cout << grid[seq1_len][seq2_len] << endl;
  }
}