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++: #include<iostream>
#include<queue>

using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for(int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while( !q.empty() ) {
        u = q.front(); q.pop();
        for (int v = 0; v < n; v++) {
            if( M[u][v] == 0 || d[v]!= INFTY ) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << (d[i] == INFTY ? (-1) : d[i]) << endl;
    }
}

int main() {
    int u, k, v;

    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}

C++: #include<stdio.h>
#include<string.h>
    
int LCS(char *X, char *Y){
  int i,j,m,n,c[1001][1001];
  m = strlen(X);
  n = strlen(Y);
      
  for(i=0; i<m; i++){
    c[i][0] = 0;
  }
  for(j=0; j<n; j++){
    c[0][j] = 0;
  }
    
  for(i=1;i<m+1;i++){
    for(j=1;j<n+1;j++){
      if (X[i-1]==Y[j-1]) c[i][j]=c[i-1][j-1]+1;
      else if (c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
    }
  }
  return c[i-1][j-1];
}
    
int main(){
  int i, q;
  char X[1001], Y[1001];
      
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%s", X);
    scanf("%s", Y);
    printf("%d\n", LCS(X, Y));
    
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#define MAX 1000
using namespace std;

int LCS(string X, string Y) {
    int i, j, maxl=0;
    int C[MAX+1][MAX+1];

    int X_len = X.size();
    int Y_len = Y.size();
    X = ' ' + X;
    Y = ' ' + Y;
    for (i=0; i<=X_len; i++) C[i][0]=0;
    for (j=1; j<=Y_len; j++) C[0][j]=0;

    for (i=1; i<=X_len; i++) {
        for (j=1; j<=Y_len; j++) {
            if (X[i]==Y[j]) {
                C[i][j]=C[i-1][j-1]+1;
                maxl = max(C[i][j], maxl);
            } else C[i][j]=max(C[i-1][j], C[i][j]);
        }
    }

    return maxl;
}

int main() {
    int n, i;
    string X, Y;
    
    cin >> n;
    for (i=0; i<n; i++) {
        cin >> X >> Y;
        cout << LCS(X, Y) << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
//#define Max 2000000
using namespace std;
int dp[1001][1001];
char x[1000],y[1000];
void init(){
    for(int i=0;i<1000;i++)
        for(int j=0;j<1000;j++)
            dp[i][j]=0;
}
void LCS(){
    int m=strlen(x);
    int r=strlen(y);
    for(int i=1;i<=m;i++)
        for(int j=1;j<=r;j++)
        {
            if(x[i-1]==y[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
}
int main()
{
    int q;
    cin>>q;
    while((q--)>0){
        cin>>x;
        cin>>y;
        init();
        LCS();
        cout<<dp[strlen(x)][strlen(y)]<<endl;
    }
}