Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	for q := ReadInt(); q > 0; q-- {
		x, y := ReadString(), ReadString()
		fmt.Println(LCS(x, y))
	}
}

func LCS(x, y string) int {
	dp := make([][]int, len(x)+1)
	for i := 0; i < len(x)+1; i++ {
		dp[i] = make([]int, len(y)+1)
	}
	for i := 0; i < len(x); i++ {
		for j := 0; j < len(y); j++ {
			dp[i+1][j+1] = Max(dp[i+1][j], dp[i][j+1])
			if x[i] == y[j] {
				dp[i+1][j+1] = Max(dp[i+1][j+1], dp[i][j]+1)
			}
		}
	}
	return dp[len(x)][len(y)]
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

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

using namespace std;
int LCS(const char* a,const char* b)
{
    int m=strlen(a); int n=strlen(b); //i???????¬????a????????????j???????¬????b?????????
    int c[m+1][n+1]; //c??°???????????¨?????°???????¬????a??????i??????????¬????b??????j????????´???LCS
    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=0;i<m;i++)
        for(int j=0;j<n;j++)
        {
            if(a[i]==b[j]) c[i+1][j+1]=c[i][j]+1;
            else
            {
                c[i+1][j+1]=max(c[i][j+1],c[i+1][j]);
            }
        }
    return c[m][n];

}
int main()
{
    char *a=new char[1001];
    char *b=new char[1001];
    int q;
    while(cin>>q)
    {
        for(int i=0;i<q;i++)
        {
            cin>>a>>b;
            cout<<LCS(a,b)<<endl;
        }
    }
}

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

int Ics(string X, string Y) {
	int c[101][101];
	int m = X.length();
	int n = Y.length();
	int maxl = 0;

	X = ' ' + X;
	Y = ' ' + Y;
	for (int i = 1; i <= m; i++) c[i][0] = 0;
	for (int j = 1; j <= n; j++) c[0][j] = 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 if (c[i - 1][j] >= c[i][j - 1])
				c[i][j] = c[i - 1][j];
			else 
				c[i][j] = c[i][j - 1];

			maxl = max(maxl,c[i][j]);
		}
		
	}
	return maxl;
}

int main() {
	int n;
	string x, y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;

		cout << Ics(x, y) << endl;
	}

	
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 301000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
//union_find
int par[100];
int depth[100];
ll N;
ll x[20],c[20],v[20];
string s,t;

int lcs(string x, string y){
    int dp[1010][1010];
    int m = x.size();
    int n = y.size();
    int mx = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i = 0; i <= m; i++) dp[i][0] = 0;
    for(int i = 1; i <= n; i++) dp[0][i] = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(x[i] == y[i]){
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
            mx = max(mx, dp[i][j]);
        }
    }
    return mx;
}
int main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s >> t;
        cout << lcs(s,t) << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {

    int n;
    string str1, str2;

    cin >> n;

    for(int cnt = 0; cnt < n; ++cnt) {

        cin >> str1 >> str2;

        int dp[str1.size() + 1][str2.size() + 1];

        for(int i = 0; i <= str1.size(); ++i) {
            dp[i][0] = 0;
        }

        for(int i = 0; i <= str2.size(); ++i) {
            dp[0][i] = 0;
        }

        for(int i = 1; i <= str1.size(); ++i) {
            for(int j = 1; j <= str2.size(); ++j) {
                if(str1[i - 1] == str2[j - 1]) {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                } else {
                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
        }

        cout << dp[str1.size()][str2.size()] << endl;

    }

}

C++: 
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C&lang=jp




#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

const int MAX_q=160;
const int MAX_L=1010;
bool done[MAX_L][MAX_L];
int memo[MAX_L][MAX_L];
int q;
string x,y;

int LCS(int i,int j)
{
    int res;

    if(i<0) return 0;
    if(j<0) return 0;

    if (done[i][j]) return memo[i][j];

    else if(x[i]==y[j])
    {
        res=LCS(i-1,j-1)+1;
    }
    else{
        int res1=LCS(i-1,j);
        int res2=LCS(i,j-1);
        res=max(res1,res2);
    }
    done[i][j]=true;
    memo[i][j]=res;
    return res;
}

int main()
{
    int res;
    cin>>q;
    rep(i,q)
    {
        cin>>x>>y;
        res=LCS(x.length()-1,y.length()-1);
        cout<<res<<"\n";
        rep(j,MAX_L)
        {
            rep(k,MAX_L)
            {
                done[j][k]=false;
            }
        }
    }


    return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int L[1001][1001];
int getc(int i,int j){
    if(i>=0&&j>=0)
        return L[i][j];
    else
        return 0;
}
int main(){
    int N;
    string X,Y;
    cin >> N;
    for(int k=0;k<N;++k){
        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]=getc(i-1,j-1)+1;
                }
                else{
                    L[i][j]=max(getc(i-1,j),getc(i,j-1));
                }
            }
        }
        cout <<L[X.length()-1][Y.length()-1]<< endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

const int MAX_N = 1333;

int dp[MAX_N][MAX_N];

int LCS(string &s, string &t) {
    int n=s.length(); int m=t.length();
    if (!n||!m) return 0;
    memset(dp,-1,sizeof(dp));
    rep(i,n+1) dp[i][0]=0;
    rep(i,m+1) dp[0][i]=0;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (s[i-1]==t[j-1]) dp[i][j]=max({dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1]});
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    return dp[n][m];
}

int main(int argc, char const *argv[]) {
    int q;cin>>q;
    rep(i,q) {
        string s,t;
        cin>>s>>t;
        cout << LCS(s,t) << endl;
    }
    return 0;
}

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

int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int N;
  cin>>N;
  string S1,S2;
  for (int k=0; k<N; k++) {
    cin>>S1>>S2;
    int m=S1.length();
    int n=S2.length();
    S1=' '+S1;
    S2=' '+S2;
    int lcs[m+1][n+1];
    for (int i=1; i<=m; i++) {
      lcs[i][0]=0;
    }
    for (int j=1; j<=n; j++) {
      lcs[0][j]=0;
    }
    int maxl=0;
    for (int i=1; i<=m; i++) {
      for (int j=1; j<=n; j++) {
        if (S1[i]==S2[j]) {
          lcs[i][j]=lcs[i-1][j-1]+1;
        }
        else {
          lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]);
        }
        maxl=max(maxl,lcs[i][j]);
      }
    }
    cout<<maxl<<endl;
  }
  return 0;
}