Go: package main

import "fmt"

func initialize_grid(width int,height int)[][]int{
	var grid [][]int
	for i:=0;i<height+1;i++{
		var grid_row  []int
		for j:=0;j<width+1;j++{
			grid_row = append(grid_row,0)
		}
		grid = append(grid,grid_row[:])
	}
	return grid
}

func ma(x int,y int)int{
	if x >= y{
		return x
	}else{
		return y
	}
}

func main()  {
	//Take input
	var num int
	var st1,st2 string
	var string_pairs [][]string
	fmt.Scan(&num)
	for i:=0;i<num;i++{
		var string_pair []string
		fmt.Scan(&st1)
		fmt.Scan(&st2)
		string_pair = append(string_pair,st1,st2)
		string_pairs = append(string_pairs,string_pair)
	}
	//DP
	//initialize grid
	for i:=0;i<num;i++{
		string_1 := string_pairs[i][0]
		string_2 := string_pairs[i][1]

		dp := initialize_grid(len(string_2),len(string_1))

		for j:=1;j<len(string_1)+1;j++{
			for k:=1;k<len(string_2)+1;k++{
				if string_1[j-1] == string_2[k-1]{
					dp[j][k] = dp[j-1][k-1] + 1
				}else{
					dp[j][k] = ma(dp[j-1][k],dp[j][k-1])
				}
			}
		}
		fmt.Println(dp[len(string_1)][len(string_2)])
	}
}

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

using namespace std;

int main(void){
    int num;
    cin>>num;
    
    vector<vector<string>> inputData(num,vector<string>(2));

    int p=0;
    while(p<num){
        for(int i=0;i<2;i++){
            cin>>inputData[p][i];
        }
        p+=1;
    }

    int q=0;
    while(q!=num){
        int s=inputData[q][0].length();
        int t=inputData[q][1].length();
        vector<vector<int>> Table(s,vector<int>(t));

        for(int i=0;i<s;i++){
            if(inputData[q][0][0]==inputData[q][1][i]){
                Table[0][i]=1;
            }else{
                Table[0][i]=0;
            }

            if(inputData[q][0][i]==inputData[q][1][0]){
                Table[i][0]=1;
            }else{
                Table[i][0]=0;
            }
        }

        vector<int> RMax(t);
        for(int i=0;i<t;i++){
            RMax[i]=Table[0][i];
        }

        //Table作成
        for(int i=1;i<s;i++){
            int max=0;
            for(int j=1;j<t;j++){
                if(RMax[j-1]>max){
                    max=RMax[j-1];
                }
                Table[i][j]=max;
                if(inputData[q][0][i]==inputData[q][1][j]){
                    Table[i][j]+=1;
                }
            }

            for(int k=0;k<t;k++){
                if(Table[i][k]>RMax[k]){
                    RMax[k]=Table[i][k];
                }
            }
        }

        //表示
        int ans=0;
        for(int i=0;i<s;i++){
            for(int j=0;j<t;j++){
                if(Table[i][j]>ans){
                    ans=Table[i][j];
                }
            }
        }

        cout<<ans<<endl;

        // for(int i=0;i<s;i++){
        //     for(int j=0;j<t;j++){
        //         cout<<Table[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }
        q+=1;
        // cout<<endl;
    }
    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
typedef pair<int, int> P;

#define MAX 100005
#define INF INT_MAX

string x, y;
vector < vector<int> > memo;

int lcs(int xs, int ys)
{
    if (xs == 0 || ys == 0) return 0;
    if (memo[xs][ys]) return memo[xs][ys];

    int res;
    if (x[xs-1] == y[ys-1]) {
        res = lcs(xs-1, ys-1) + 1;
    } else {
        res = max(lcs(xs,ys-1), lcs(xs-1,ys));
    }
    memo[xs][ys] = res;
    return res;
}

int main(int, char**)
{
    int q;
    cin >> q;

    vector<int> ans;
    rep(i,q) {
        cin >> x >> y;
        int xs = x.size();
        int ys = y.size();
        memo.assign(xs+1, vector<int>(ys+1,0));
        ans.push_back(lcs(xs,ys));
    }

    rep(i,q) cout << ans[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

string A,B;

ll dp[1007][1007];

int LCS(string A,string B){
    REP(i,1,A.size()+1){
        REP(j,1,B.size()+1){
            if(A[i-1]==B[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    return dp[A.size()][B.size()];
}

int main(){
    ll N;cin>>N;
    rep(i,N){
        cin>>A>>B;
        cout << LCS(A,B) << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int dp[1001][1001];

int lcs(string x, string y)
{	
	int n = x.size();
	int m = y.size();

	x = " " + x;
	y = " " + y;

	for (int i = 1; i <= n; i++) dp[i][0] = 0;
	for (int j = 1; j <= m; j++) dp[0][j] = 0;

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

int main()
{
	int q;
	string s1, s2;
	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<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 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 {
				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 n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> s1 >> s2;
			cout << lcs(s1, s2) << 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();
  
  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 (X[i] == Y[j]) 
        if (i == 0 || j == 0) 
          c[i][j] = 1;
        else 
          c[i][j] = c[i - 1][j - 1] + 1;
      else
        c[i][j] = max(c[i][j - 1], c[i - 1][j]);
    }
  }
  return c[m - 1][n - 1];
}

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;
}