Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
int q;
cin >> q;
vi result(0);
while(q > 0){
  string s, t;
  cin >> s >> t;
  int ssize = s.size(), tsize = t.size();
  vvi dp(1100, vi(1100, 0));

  for(int i = 0; i < ssize; i++){
    for(int j = 0; j < tsize; j++){
      if(s.at(i) == t.at(j)) dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
      else{
        chmax(dp.at(i+1).at(j+1), dp.at(i).at(j+1));
        chmax(dp.at(i+1).at(j+1), dp.at(i+1).at(j));
      }
    }
  }

  result.push_back(dp.at(ssize).at(tsize));

  q--;
}

for(auto x: result) cout << x << endl;
  
}

C++: 
#include<iostream>

int main(){
  int n;
  std::string x,y;
  std::cin>>n;
  int a[1000][1000];
  int b[n];

  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	a[j][k]=0;
      }
    }
    for(int j=0;j<=x.size();j++){
      for(int k=0;k<=y.size();k++){
	if(x[j]==y[k]){
	  a[j+1][k+0]=a[j][k]+1;
	}else{
	  if(a[j][k+1]>a[j+1][k]){
	    a[j+1][k+1]=a[j][k+1];
	  }else{
	    a[j+1][k+1]=a[j+1][k];
	  }
	}
      }
    }
    b[i]=a[x.size()][y.size()];
  }

  for(int i=0;i<n;i++){
  std::cout<<b[i]<<"\n";
  }

  return 0;
}

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

using namespace std;

int main(){
  int n;
  int k;
  int count;
  int max;
  cin>>n;
  char X[1001];
  char Y[1001];
  for(int i=0;i<n;i++){
    cin>>X;
    cin>>Y;
    k=0;
    max=0;
    for(int a=0;X[a]!='\0';a++){
    count=0;
      for(int i=a;X[i]!='\0';i++){
	for(int j=k;Y[j]!='\0';j++){
	  if(X[i]==Y[j]){
	    count++;
	    k=j;
	    break;
	  }
	}
      }
      if(max<count)max=count;
    }
    cout<<max<<endl;
    
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

int LCS(string s,string t){
  int n=s.size(),m=t.size();
  vector<vector<int>>dp(n+1,vector<int>(m+1));
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
      if(s[i]==t[j])dp[i+1][j+1]=dp[i][j]+1;
      else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
    }
  }
  return dp[n][m];
}


void solve(){
  int t;
  cin>>t;
  while(t--){
    string s,t;
    cin>>s>>t;
    cout<<LCS(s,t)<<"\n";
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

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

using namespace std;

int dp[1501][1501];

int LCS(string x, string y){
  memset(dp, 0, sizeof(dp));
  if(x[0] == y[0])dp[0][0] = 1;
  for(int i=1;i<x.length();i++){
    dp[i][0] = dp[i-1][0];
    if(x[i] == y[0])dp[i][0] = 1;
  }
  for(int i=1;i<y.length();i++){
    dp[0][i] = dp[0][i-1];
    if(y[i] == x[0])dp[0][i] = 1;
  }
  for(int i=1;i<x.length();i++){
    for(int j=1;j<y.length();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[x.length()-1][y.length()-1];
}

int main(){
  int q;cin >> q;
  for(int i=0;i<q;i++){
    string x, y;
    cin >> x >> y;
    cout << LCS(x, y) << endl;
  }
}

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

static const N = 100;

int main(){
	int n, p[N+1], m[N+1][N+1];
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> p[i-1] >> p[i];
	}

	for (int i=1; i<=n; i++) m[i][i] = 0;
	for (int l=2; l <= n; l++){
		for (int i=1; i<=n-l+1; i++){
			int j = i + l - 1;
			m[i][j] = 1 << 21;
			for (int k = i; k<= j - 1; k++){
				m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

	return 0;
}