Go: package main

import "fmt"

func main() {
	var nPairs int
	fmt.Scanln(&nPairs)

	var a, b string
	for i := 0; i < nPairs; i++ {
		fmt.Scanln(&a)
		fmt.Scanln(&b)
		fmt.Println(lcsSize(a, b))
	}
}

func lcsSize(sa, sb string) int {
	dp := make([][]int, len(sa)+1)
	for i := 0; i <= len(sa); i++ {
		dp[i] = make([]int, len(sb)+1)
	}

	for a := 1; a <= len(sa); a++ {
		for b := 1; b <= len(sb); b++ {
			if sa[a-1] == sb[b-1] {
				dp[a][b] = dp[a-1][b-1] + 1
			} else {
				dp[a][b] = max(dp[a][b-1], dp[a-1][b])
			}
		}
	}

	return dp[len(sa)][len(sb)]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[101][101];
  
  while (flag == 0)
  {
    if (x[xn] != '\0')
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] != '\0')
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 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];
      }
      if (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}

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

using namespace std;

int main(){
    int q;
    scanf("%d", &q);
    while(q--)
    {
        string X, Y;
        cin>>X>>Y;
        int table[X.length() + 1][Y.length() + 1];
        for(int i=0; i<Y.length() + 1; i++) table[0][i] = 0;
        for(int i=1; i<X.length() + 1; i++)
        {
            table[i][0] = 0;
            for(int j=1; j<Y.length() + 1; j++)
            {
                if(X[i-1] == Y[j-1]) table[i][j] = table[i-1][j-1] + 1;
                else table[i][j] = max(table[i-1][j], table[i][j-1]);
            }
        }
        printf("%d\n", table[X.length()][Y.length()]);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

vector<vector<int> > DP(1000,vector<int>(1000));

void init(int n,int m){
    rep(i,n){
        rep(j,m){DP[i][j]=-1;}
    }
}

int LCS(char a[],char b[],int n,int m){
    if(n<0||m<0)return 0;
    if(DP[n][m]!=-1)return DP[n][m];
    if(a[n]==b[m])return DP[n][m]=1+LCS(a,b,n-1,m-1);
    return DP[n][m]=max(LCS(a,b,n-1,m),LCS(a,b,n,m-1));
}

int main(){
    int q;cin>>q;
    char s[1001],t[1001];
    rep(i,q){
        cin>>s>>t;
        int n=strlen(s),m=strlen(t);
        init(n,m);
        int ans=LCS(s,t,n-1,m-1);
        printf("%d\n",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;
}