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 <string.h>
using namespace std;

#define MAX_NUM 1001
int fLength;
int sLength;

int memo[MAX_NUM][MAX_NUM];
string f, s;

/*******************
  Longest Common Subsequence
  ??¨??????????????§??????????????????(??¨??????????????§?????????)
 *********************/

void solve() {
  for(int i = 0; i < fLength; i++) {
    for(int j = 0; j < sLength; j++) {
      if(f[i] == s[j]) {
        memo[i + 1][j + 1] = memo[i][j] + 1;
      }
      else {
        memo[i + 1][j + 1] = max(memo[i + 1][j], memo[i][j + 1]);
      }
    }  
  }
}


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


  //?????????
  memset(memo, 0, sizeof(memo));
  for(int i = 0; i < n; i++) {
    cin >> f >> s;
    fLength = f.size();
    sLength = s.size();
    solve();
    cout << memo[fLength][sLength] << endl;
  }
  return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int q; cin >> q;
    VS X(q), Y(q); REP(i,q) cin >> X[i] >> Y[i];

    REP(k,q){
        int dp[X[k].size()+1][Y[k].size()+1]; REP(i,X[k].size()+1)REP(j,Y[k].size()+1) dp[i][j] = 0;
        REP(i,X[k].size())REP(j,Y[k].size()){
            if(X[k][i] == Y[k][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[X[k].size()][Y[k].size()] << endl;
    }
    return 0;
}

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

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

  for(int i=0;i<n;i++) {
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;
    int seq1_len = 0;
    int seq2_len = 0;
    while(seq1[seq1_len] != '\0')
      seq1_len++;
    while(seq2[seq2_len] != '\0')
      seq2_len++;

    /*
    cout << "length" << endl;
    cout << seq1_len << endl;
    cout << seq2_len << endl;
    */

    int lcs[seq1_len+1][seq2_len+1];
    for(int i=0;i<=seq1_len;i++)
      lcs[i][0] = 0;
    for(int i=0;i<=seq2_len;i++)
      lcs[0][i] = 0;

    for(int i=1;i<=seq1_len;i++) {
      for(int j=1;j<=seq2_len;j++) {
        int s1_it = i-1;
        int s2_it = j-1;
        if(seq1[s1_it] == seq2[s2_it]) {
          lcs[i][j] = lcs[i-1][j-1] + 1;
        }
        else {
          lcs[i][j] = max(lcs[i][j-1],lcs[i-1][j]);
        }
      }
    }
    /*
    cout << "lcs[i][j]" << endl;
    for(int i=0;i<=seq1_len;i++) {
      for(int j=0;j<=seq2_len;j++) {
        cout << lcs[i][j] << " ";
      }
      cout << endl;
    }
    */

    cout << lcs[seq1_len][seq2_len] << endl;
  }
}

C++: #include <iostream>
using namespace std;

#define MAX_Q 150
#define MAX_LEN 1000
string s, t;
int dp[MAX_LEN+1][MAX_LEN+1];

int align_dp() {
    fill((int*)dp, (int*)(dp+MAX_LEN+1), 0);
    // dp[i][j] := i-1番目、j-1番目までの文字で最長
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = max(dp[i][j] + 1, max(dp[i+1][j], dp[i][j+1]));
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    return dp[s.size()][t.size()];
}

int main() {
    int q;
    cin >> q;
    int res[MAX_Q+1];
    for (int i = 0; i < q; i++) {
        cin >> s;
        cin >> t;
        res[i] = align_dp();
    }
    for (int i = 0; i < q; i++)
        cout << res[i] << endl;
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
const int N=1e3+10;
int max(int a,int b){return a>b?a:b;}
int main(){
    int n,dp[N][N];
    string a,b;
    scanf("%d",&n);
    while(n--){
        cin>>a>>b;
        a='!'+a;
        b='@'+b;
        for(int i=0;i<a.size();i++)dp[i][0]=0;
        for(int i=0;i<b.size();i++)dp[0][i]=0;
        for(int i=1;i<a.size();i++)for(int j=1;j<b.size();j++){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            if(a[i]==b[j])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
        printf("%d\n",dp[a.size()-1][b.size()-1]);
    }
}

C++: 
#include<iostream>

int main(){
  int n;
  std::string x,y;
  std::cin>>n;
  int a[1000][1000];
  int b[n];

  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	a[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  a[j][k]=a[j-1][k-1]+1;
	}else{
	  if(a[j-1][k]>a[j][k-1]){
	    a[j][k]=a[j-1][k];
	  }else{
	    a[j][k]=a[j][k-1];
	  }
	}
      }
    }
    b[i]=a[x.size()-1][y.size()-1];
  }

  for(int i=0;i<n;i++){
  std::cout<<b[i]<<"\n";
  }

  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int MAX = 1000+5;
int DP[MAX][MAX];
string s1,s2;
int LCS(){
	memset(DP,0,sizeof(DP));
	int l1 = s1.size(),l2 = s2.size();
	int maxl = 0;
	s1 = ' '+s1;
	s2 = ' '+s2;
	for(int i = 1;i <= l1;i++)	DP[i][0] = 0;
	for(int j = 1;j <= l2;j++)	DP[0][j] = 0;
	for(int i = 1;i <= l1;i++){
		for(int j = 1;j <= l2;j++){
			if(s1[i] == s2[j])
				DP[i][j] = DP[i-1][j-1] + 1;
			else
				DP[i][j] = max(DP[i-1][j],DP[i][j-1]);
			maxl = max(DP[i][j],maxl);
		}
	}
	return maxl;
}
int main(int argc, char const *argv[])
{
	int T;
	cin >> T;
	while(T--){
		cin >> s1 >> s2;
		cout << LCS() << endl;
	}
	return 0;
}