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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll q;
  cin >> q;
  rep(_, q) {
    string x, y;
    cin >> x >> y;
    ll m = x.size(), n = y.size();
    vector<vl> dp(m + 1, vl(n + 1, 0));
    rep(i, m) rep(j, n) {
      if(x[i] == y[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[m][n] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v
#define NUM(x,v) (POSU(x,v)-POSL(x,v))
const ll INF=1e9+7;
const ll N = 1002;
const ll M = 21;
ll q,dp[N][N];
string x,y;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>q;
	FOR(k,0,q){
		cin>>x>>y;
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				dp[i][j]=0;
			}
		}
		FOR(i,0,x.size()+1){
			FOR(j,0,y.size()+1){
				if(i==0||j==0)dp[i][j]=0;
				else{
					if(x[i]==y[j])dp[i][j] = max(dp[i-1][j]+1,dp[i][j-1]+1);
					else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
				} 
			}
		}
		cout<<dp[x.size()][y.size()]<<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 = 0; i <= m; i++) c[i][0] = 0;
    for(int i = 1; i <= n; i++) c[0][i] = 0;
    cout << "test" << endl;
    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 <fstream>
#include <string>
using namespace std;

int lcs(string x, string y) {
  int dp[1001][1001];
  int maxl=0;
  x = ' ' + x;
  y = ' ' + y;
  for (int i = 0; i < x.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 0; i < y.size(); i++)
  {
    dp[i][0] = 0;
  }
  for (int i = 1; i < x.size(); i++)
  {
    for (int j = 1; j < y.size(); j++)
    {
      if (x[i] == y[j]) {
        dp[i][j] = dp[i-1][j-1] + 1;
      }
      else {
        dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
      }
    maxl = max(maxl, dp[i][j]);
    }
    
  }
  return maxl;
}

int main(){

  //std::ifstream in ("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string a, b;
    cin >> a >> b;
    cout << lcs(a, b) << endl;
  }
  return 0;
  
}

C++: #include<iostream>
#include<vector>
#include<limits.h>
#include<string>
using namespace std;

int LCS(string a, string b){
	int n=a.size();
	int m=b.size();
	int T[n+1][m+1];
	int i,j;
	for (i=0;i<n+1;i++) T[i][0]=i;
	for (j=0;j<m+1;j++) T[0][j]=j;
	for (i=1;i<n+1;i++){
		for (j=1;j<m+1;j++){
			int min=T[i-1][j]+1;
			if (min>T[i][j-1]+1){
				min=T[i][j-1]+1;
			}
			if ((a[i-1]==b[j-1])&&(min>T[i-1][j-1]+1)){
				min=T[i-1][j-1]+1;
			}
			T[i][j]=min;
		}
	}
	return n+m-T[n][m];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,i;
	cin >> n;
	
	string a,b;
	for (i=0;i<n;i++){
		cin >> a >> b;
		cout << LCS(a,b) << endl;
	}
	return 0;
}

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

void solve(){
    string S, T;
    cin >> S;
    cin >> T;

    int dp[1001][1001];
    dp[0][0] = 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;
}

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

    for (int i = 0; i < q; i++)
        solve();
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

//-----------------------------------------
int dp[1000+10][1000+10];



//-----------------------------------------
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string s, t;
    cin >> s >> t;
    int ss = s.size();
    int st = t.size();
    for(int i=0;i<=ss;i++){
      for(int j=0;j<=st;j++){
        if(i==0 || j==0) dp[i][j] = 0;
        else dp[i][j] = -1;
      }
    }
    for(int i=1;i<=ss;i++){
      for(int j=1;j<=st;j++){
        if(s[i-1] == t[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[ss][st] <<endl;
  }

  return 0;
}