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<iostream>
#include<string>
#include<algorithm>
using namespace std;

string X, Y;
int v[1001][1001];

int  dp(string X, string Y) {
	int n = X.size();
	int m = Y.size();
	memset(v, 0, sizeof(v));
	for (int i = 0; i <= n; i++) {
		v[i][0] = 0;											///０のテーブル
		for (int j = 0; j <= m; j++) {
			v[0][j] = 0;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (X[i-1] == Y[j-1]) {
				v[i][j] = v[i - 1][j - 1] + 1;
			}
			else {
				v[i][j] = max(v[i - 1][j], v[i][j - 1]);
			}
		}
	}
	return v[n][m];
}

int main(void)
{
	int x;
	cin >> x;
	
	for (int i = 0; i < x; i++) {
		cin >> X >> Y;
		int ans = dp(X, Y);
		cout << ans << endl;
	}
	
	system("pause");
}

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

using namespace std;                                         
                                                             
//L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS                        
int L[1000][1000]={};                                        
int main(){
  int testnum;
  cin>>testnum;                                              
  for(int t=0;t<testnum;++t){                                
    string X,Y;                                              
    cin>>X>>Y;
    
    for(int i=0;i<X.length();++i){                           
      for(int j=0;j<Y.length();++j){                         
        if(X[i]==Y[j])
          L[i][j] = 1 + L[i-1][j-1];                         
        else
          L[i][j] = max(L[i][j-1],L[i-1][j]);
      }
    }

    cout << L[X.length()-1][Y.length()-1] << endl;
  }

  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 res = 0;

    x = ' ' + x;
    y = ' ' + y;

    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 = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (x[i] == y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i][j - 1], c[i - 1][j]);
            }
            res = max(res, c[i][j]);
        }
    }

    return res;
}

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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int n, m;
string s, t;
const int n_max = 1000;
const int m_max = 1000;

int main() {
	cin >> n;
	for(int k=0; k<n; ++k){
        cin >> s >> t;
        int dp[n_max+1][m_max+1] = {0};
	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] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}
        cout << dp[s.size()][t.size()] << endl;
    }
	

	return 0;
}

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

#define MAX 1000

int dp[MAX+1][MAX+1];

int lcs(char x[], char y[]){
  for(int i = 0; i<=strlen(x); i++){
    dp[i][0] == 0;
    dp[0][i] == 0;
  }

  for(int i = 1; i<=strlen(x); i++){
    for(int j = 1; j<=strlen(y); j++){
      dp[i][j] = (x[i] == y[j]) ? dp[i-1][j-1] + 1 :
                                  max(dp[i-1][j],dp[i][j-1]);
    }
  }

  return dp[strlen(x)][strlen(y)];
}

int main(){

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

  char X[MAX + 1];
  char Y[MAX + 1];
  for(int i=0; i<q; i++){
    scanf("%s\n%s\n", X, Y);
    printf("%d\n", lcs(X, Y));
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <string>
#include <utility>
using namespace std;

int n;
string a,b;


int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		int t[1010][1010] = {};
		for (int i = 0; i < a.length(); i++){
			for (int j = 0; j < b.length(); j++){
				if (i == 0 || j == 0)t[i][j] = 0;
				else if (a[i] == b[j]){
					t[i + 1][j + 1] = t[i][j] + 1;
				}
				else t[i + 1][j + 1] = max(t[i + 1][j], t[i][j + 1]);
			}
		}
		cout << t[a.length()][b.length()] << endl;
	}
	return 0;
}

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

#define MAX 1000

int lcs(string x, string y) {
  int c[MAX + 1][MAX + 1];
  int m = x.size();
  int n = y.size();
  int maxl = 0;
  x = ' ' + x;
  y = ' ' + y;
  for ( int i = 1; i <= m; i++ ) {
    for ( int j = 1; j <= n; 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]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }

  return maxl;
}

int main() {
  string s1, s2;
  int q;
  cin >> q;

  for ( int i = 0; i < q; i++ ) {
    cin >> s1 >> s2;
    cout << lcs(s1, s2) << endl;
  }

  return 0;
}

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

int mem[1005][1005];

void pre(int x,int y){
  for(int i=0;i<=x;i++){
    for(int j=0;j<=y;j++){
      mem[i][j]=0;
    }
  }

  return;
}

main(){
  int n;
  string temp;
  string x,y;

  cin >> n;
  
  for(int cnt=0;cnt<n;cnt++){
    
    x="0";
    y="0";
    cin >> temp;
    x+=temp;
    cin >> temp;
    y+=temp;

    pre((int)x.size(),(int)y.size());

    for(int i=1;i<=x.size();i++){
      for(int j=1;j<=y.size();j++){

	if(x[i]==y[j]){
	  mem[i][j]=mem[i-1][j-1]+1;
	}
	mem[i][j]=max(mem[i][j],max(mem[i-1][j],mem[i][j-1]));

      }
    }

    cout << mem[x.size()][y.size()]-1 << endl;
  }

  return (0);
}

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

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