Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

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 = s.size();
    int n = t.size();
    int mx = 0;
    x = ' ' + x;
    y = ' ' + y;
    for(int i = 0; i <= m; i++){
        for(int j = 0; j <= n; j++){
            dp[i][j] = 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;
    }
}

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

int dp[1010][1010];

int main()
{
  int q;
  string x,y;

  cin >> q;

  for(int t = 0;t < q;t++){
    cin >> x;
    cin >> y;

    memset(dp, 0, sizeof(dp));
    
    for(int i = 1;i <= x.size();i++){
      for(int j = 1;j <= y.size();j++){

	if(x[i-1] == y[j-1]){
	  dp[i][j] = dp[i-1][j-1]+1;
	}
	else if(dp[i-1][j] <= dp[i][j-1]){
	  dp[i][j] = dp[i][j-1];
	}
	else{
	  dp[i][j] = dp[i-1][j];
	}
      }
    }
    cout << dp[x.size()][y.size()] << endl;
  }
  return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int q;
  cin >> q;
  while (q--) {
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.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 (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[n][m] << 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, i, j;

  x = ' ' + x;
  y = ' ' + y;

  for(i=0;i<=m;i++) c[i][0] = 0;
  for(j=1;j<=n;j++)c[0][j] = 0;
  
  for(i=1;i<=m;i++){
    for(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();
  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;
  int A[n];
  for(int i = 0; i < n; i++){
    cin >> s1 >> s2;
    A[i] = lcs(s1, s2);
  }
  for(int i = 0; i < n; i++) cout << A[i] << endl;
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
using namespace std;
void input(string &x,string &y){
	cin>>x>>y;
}
int lcs(string x,string y){
	vector<vector<int>> tb(vector<vector<int>>((int)x.size()+1,vector<int>(y.size()+1,0)));
	for(int i=1;i<(int)x.size()+1;i++){
		for(int j=1;j<(int)y.size()+1;j++){
			if(x[i-1]==y[j-1])  tb[i][j]=tb[i-1][j-1]+1;
			else tb[i][j]=max(tb[i-1][j],tb[i][j-1]);
		}
	}
	return tb[(int)x.size()][(int)y.size()];
}
int main(){
	int q;
	cin>>q;
	string x,y;
	for(int i=0;i<q;i++){
		input(x,y);
		cout<<lcs(x,y)<<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 = 0; 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;
    }
    // for (int i = 0; i < n; i++) {
    //     cout << Lcs(s1[i], s2[i]) << endl;
    // }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt;
  cin>>cnt;
  while(cnt--){
    string a,b;
    cin>>a>>b;
    int dp[1000][1000]={};
    for(int i=0;i<b.size();i++){
      int nm=0;
      for(int j=0;j<a.size();j++){
	if(a[j]==b[i])dp[i][j]=nm+1;
	if(i){
	  dp[i][j]=max(dp[i][j],dp[i-1][j]);
	  nm=max(nm,dp[i-1][j]);
	}
      }
    }
    int ans=0;
    for(int i=0;i<a.size();i++)ans=max(ans,dp[b.size()-1][i]);
    cout<<ans<<endl;
   
  }
  
  return 0;
}

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