Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, q;
string s, t;

int main() {
    cin >> q;

    REP(i, q) {
        cin >> s >> t;
        int ss = s.size(), st = t.size();
        VVi dp(ss+1, Vi(st+1, 0));
        REP2(i, 1, ss+1) REP2(j, 1, st+1) {
            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-1], dp[i-1][j], dp[i][j-1]});
            }
        }

        std::cout << dp[ss][st] << '\n';
    }

    return 0;
}

C++: #include<string>
#include<iostream>
#include<algorithm>
using namespace std;
static const int N = 1001;
int dp[N][N];
int stl(string a, string b) {
	a = " " + a;
	b = " " + b;
	for (int i = 0; i < a.length(); i++) {
		for (int j = 0; j < b.length(); j++)
			dp[i][j] = 0;
	}
	for (int i = 1; i < a.length(); i++) {
		for (int m = 1; m < b.length(); m++) {
			if (a[i] == b[m]) dp[i][m] = dp[i - 1][m - 1] + 1;
			else dp[i][m] = max(dp[i][m - 1], dp[i - 1][m]);
		}
	}
	return dp[a.length() - 1][b.length() - 1];
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string a, b;
		cin >> a >> b;
		cout << stl(a, b)<<endl;
	}
}

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=ma(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 <bits/stdc++.h>
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

int n, w;
vector<vector<int>> dp(10000, vector<int>(10000, -1));
vector<int> vv;
vector<int> wv;

void solve(){
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < w; j++) {
      if(j < wv[i]){
        dp[i][j] = dp[i+1][j];
      }else{
        dp[i][j] = max(dp[i+1][j], dp[i+1][j-wv[i]] + vv[i]);
      }
    }
  }
}

int main(){
  cin >> n >> w;
  for (int i = 0; i < n; i++)
  {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    wv.push_back(tmp1);
    vv.push_back(tmp2);
  }

  solve();
  cout << dp[0][w] << endl;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;++i){
		string a,b;
		int al,bl;
		cin >> a >> b;
		a = ' ' + a;b = ' ' + b;
 		al = a.length();bl = b.length();
		vector<vector<int> > dp;
		dp.resize(al);
		for(int i=0;i<al;++i){
			dp[i].resize(bl);
		}
		for(int i=0;i<al;++i)dp[i][0] = 0;
		for(int i=0;i<bl;++i)dp[0][i] = 0;
		for(int i=1;i<al;++i){
			for(int j=1;j<bl;++j){
				if(a[i]==b[j])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
		cout << dp[al-1][bl-1] << endl;
	}
}

C++: 
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>

using namespace std;
typedef unsigned long long ull;
typedef  long long ll;

int lcs(string x, string y) {
	//puts("c");
	vector<vector<int>> c;
	c.resize(1001);
	for (int i = 0; i < c.size(); i++) {
		c[i].resize(1001);
	}
	//puts("b");
	x = ' ' + x;
	y = ' ' + y;
	//puts("a");
	for (int i = 0; i < x.size(); i++) {
		c[i][0] = 0;
	}
	for (int i = 0; i < y.size(); i++) {
		c[0][i] = 0;
	}
	for (int i = 1; i < x.size(); i++) {
		for (int j = 1; j < y.size(); 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[x.size() - 1][y.size() - 1];
	
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		string a,b;
		cin >> a;
		cin >> b;
		cout << lcs(a,b) << endl;
	}
	return 0;

}

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

int lcs(string a,string b){
  int c[1001][1001];
  int m=a.size(),n=b.size();
  int mx=0;
  a=' '+a;
  b=' '+b;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(a[i]==b[j]){
	c[i][j]=c[i-1][j-1]+1;
      }else{
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      mx=max(mx,c[i][j]);
    }
  }
  return mx;
}


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