Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	int n;
	cin >> n;
	rep(i, n) {
		string x, y;
		cin >> x >> y;
		int xl = x.length(), yl = y.length();
		vector<vector<int>> com(xl, vector<int>(yl, 0));
		rep(j, xl) {
			rep(k, yl) {
				if (j == 0) {
					if (k == 0) {
						if (x[j] != y[k]) {
							com[j][k] = 0;
						}
						else {
							com[j][k] = 1;
						}
					}
					else {
						if (com[j][k-1] == 1) {
							com[j][k] = 1;
						}
						else {
							if (x[j] != y[k]) {
								com[j][k] = 0;
							}
							else {
								com[j][k] = 1;
							}
						}
					}
				}
				else {
					if (k == 0) {
						if (com[j-1][k] == 1) {
							com[j][k] = 1;
						}
						else {
							if (x[j] == y[k]) {
								com[j][k] = 1;
							}
							else {
								com[j][k] = 0;
							}
						}
					}
					else {
						if (x[j] == y[k]) {
							com[j][k] = com[j - 1][k - 1]+1;
						}
						else {
							com[j][k] = max(com[j][k - 1], com[j - 1][k]);

						}
					}
				}
				//cout << com[j][k] <<" ";
			}
			//cout << x[j]<<endl;
		}
		cout << com[xl - 1][yl - 1] << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }


int main() {
	
	int q;
	cin >> q;
	for(int cnt=0; cnt<q; cnt++){
		string s,t;
		cin >> s >> t;
		vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1));
		for(int i=0; i<s.size(); i++){
			for(int j=0; j<t.size(); j++){
				if(s.at(i)==t.at(j)) dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
				else  dp.at(i+1).at(j+1) = max( dp.at(i).at(j+1) , dp.at(i+1).at(j) );
			}
		}
		cout << dp.at(s.size()).at(t.size())<<endl;
	}
}

C++: //ALDS1_10_C:Longest Common Subsequence
#include <bits/stdc++.h>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int main(){
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string X,Y;
        cin >> X >> Y;
        int lcs[1001][1001];
        for(int i=0; i<=X.size(); i++){
            for(int j=0; j<=Y.size(); j++){
                if(i == 0 || j == 0) lcs[i][j] = 0;
                else if(X[i-1] == Y[j-1]) lcs[i][j] = lcs[i-1][j-1] + 1;
                else lcs[i][j] = max(lcs[i][j-1], lcs[i-1][j]);
            }
        }
        cout << lcs[X.size()][Y.size()] << endl;
    }
}

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

int main(void){
  string st1, st2;
  int q, val[151][151];

  cin >> q;

  for(int i=0; i<q; i++){
    cin>>st1;
    cin>>st2;

    for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){

	if(j==0 || k==0) val[j][k] = 0;
	else{

	  if(st1[j-1] == st2[k-1]){
	    val[j][k] = max(val[j-1][k], val[j][k-1]+1);
	  }else{
	    val[j][k] = max(val[j-1][k], val[j][k-1]);
	  }
	}

	if(val[j][k] >= st1.length() || val[j][k] >= st1.length()){
	  val[j][k] = min(st1.length(), st2.length());
	}
      }
    }

    /*
      for(int j=0; j<=st1.length(); j++){
      for(int k=0; k<=st2.length(); k++){
      cout << val[j][k] << " ";
      }
      cout << "\n";
      }
    */

    cout << val[st1.length()][st2.length()] << "\n";
  }

  return 0;
}

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

int lcs(string X, string Y) {
	int dp[1000 + 1][1000 + 1];
	int max = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for (unsigned int i = 1; i <= X.size() - 1; i++)
		dp[i][0] = 0;

	for (unsigned int i = 1; i <= Y.size() - 1; i++)
		dp[0][i] = 0;
	for (unsigned int i = 1; i <= X.size() - 1; i++) {
		for (unsigned int j = 1; j <= Y.size() - 1; j++) {
			if (X[i] == Y[i])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else if (dp[i - 1][j] >= dp[i][j - 1])
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = dp[i][j - 1];

			max = (max < dp[i][j]) ? dp[i][j] : max;
		}
	}

	return max;
}

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

	for (int i = 0; i < N; i++) {
		string X, Y;
		cin >> X >> Y;

		cout << lcs(X, Y) << endl;
	}

	return 0;
}

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

int c[N][N];
int lcs(char x[],char y[]){

    int lenx = strlen(x+1);
    int leny = strlen(y+1);

    for (int i=0; i<=lenx; i++) {
        c[i][0] = 0;
    }
    for(int j=1;j<=leny;j++){
        c[0][j] = 0;
        
    }

    for(int i=1;i<lenx;i++){
        for(int j=1;j<leny;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]);
        }
    }
    return c[lenx][leny];
}
int main(){
    int q;
    char x[N],y[N];
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        gets(x+1);
        gets(y+1);
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N (1010)

int dp[MAX_N][MAX_N];

int main()
{
    int q;
    scanf("%d", &q);

    for ( int t = 0; t < q; t++ ) {
	string X;
	string Y;
	cin >> X;
	cin >> Y;

	dp[0][0] = ( X[0] == Y[0] ) ? 1 : 0;

	for ( int i = 1; i < X.size(); i++ ) {
	    dp[i][0] = ( X[i] == Y[0] ) ? 1 : dp[i-1][0];
	}
	
	for ( int i = 1; i < Y.size(); i++ ) {
	    dp[0][i] = ( X[0] == Y[i] ) ? 1 : dp[0][i-1];
	}

	for ( int i = 1; i < X.size(); i++ ) {
	    for ( int j = 1; j < Y.size(); j++ ) {
		dp[i][j] = ( X[i] == Y[j] ) ? dp[i-1][j-1] + 1 : max( dp[i][j-1], dp[i-1][j] );
	    }
	}

	printf("%d\n", dp[X.size()-1][Y.size()-1]);
    }

    return 0;
}