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 <stdio.h>
#include <string.h>
#define N 1010
char a[N];
char b[N];
int dp[N][N];
//int LCS(int i, int j){
//    if(i == -1 || j == -1) return 0;
//    if(a[i] == b[j]) return LCS(i-1, j-1) + 1;
//    else return LCS(i-1, j) > LCS(i, j-1) ? LCS(i-1, j) : LCS(i, j-1);
//}
int main(){
    int k;
    scanf("%d", &k);
    while(k--){
        scanf("%s", a);
        scanf("%s", b);
        int n = strlen(a);
        int m = strlen(b);
        for(int i = n-1; i >= 0; i--) a[i+1] = a[i];
        for(int i = m-1; i >= 0; i--) b[i+1] = b[i];
        int max = n > m ? n : m;
        for(int i = 0; i <= max; i++) dp[0][i] = dp[i][0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(a[i] == b[j]) dp[i][j] = dp[i-1][j-1] + 1;
                else {
                    dp[i][j] = dp[i-1][j] > dp[i][j-1] ? dp[i-1][j] : dp[i][j-1];
                }
            }
        }
        printf("%d\n", dp[n][m]);
        //printf("%d\n", LCS(strlen(a)-1, strlen(b)-1));
    }
    return 0;
}

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

const int MAX_L=1000;//?????????????????§??????

vector<vector<int> > DP(MAX_L, vector<int>(MAX_L, -1));
string A;//?????????????????????????????????
string B;

//A???a???????????¨????????\??????B???b???????????¨????????\??????????????§????????§?????¨????????????????????????????????????
//m?????????????????????????????±??????????????????
int dev(int a, int b){
	if(DP[a][b]<0){
		int maxi= 0;
		//???????????????????????§??????
		for(int c='a'; c<='z'; ++c){
			int posa = A.find(c,a);
			int posb = B.find(c,b);
			if(posa>=0 && posb>=0){
				int tmp = dev(posa+1,posb+1);
				maxi = max(maxi, tmp+1);
			}
		}
		DP[a][b]=maxi;
	}
	return DP[a][b];
}

int main(){
	int q;
	cin >> q;
	vector<int> ans(q);
	REP(i,q){
		REP(k,MAX_L){
			REP(l,MAX_L){
				DP[k][l] = -1;
			}
		}
		cin>>A>>B;
		ans[i]=dev(0,0);
	}
	REP(i,q){
		cout<<ans[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)


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

  rep(i,q){
      string X,Y;
      cin >> X >> Y;
      int xl,yl;
      xl = X.size();
      yl = Y.size();

      vector<vector<int>> dp(xl+1,vector<int>(yl+1));
      for(int i = 0;i < xl;i++){
          for(int j = 0;j < yl;j++){
              if (X.at(i) == Y.at(j)){
                  dp.at(i+1).at(j+1) = max(dp.at(i).at(j)+1,dp.at(i+1).at(j+1));
              }
              dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j+1),dp.at(i+1).at(j));
              dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j+1),dp.at(i).at(j+1));
          }
      }
      cout << dp.at(xl).at(yl) << endl;


  }
  
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;


int main() {
    int t;
    cin >> t;
    rep(i,0,t){
        string s1,s2;
        cin >> s1 >> s2;
        int n1 = s1.size();
        int n2 = s2.size();
        int dp[n1+1][n2+1];
        rep(j,0,n1+1){
            rep(k,0,n2+1){
                dp[j][k] = 0;
            }
        }
        rep(j,0,n1){
            rep(k,0,n2){
                if(s1[j] == s2[k]){
                    dp[j+1][k+1] = max(dp[j+1][k], dp[j][k] + 1);
                }else{
                    dp[j+1][k+1] = max(dp[j+1][k], dp[j][k+1]);
                }
            }
        }
        // rep(j,0,n1+1){
        //     rep(k,0,n2+1){
        //         cout << dp[j][k] << " ";
        //     }
        //     cout << "\n";
        // }
        cout << dp[n1][n2] << "\n";
    }
}

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C
// Dynamic Programming - Longest Common Subsequence

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const ui64 MAX_N = 1000;
ui64 dp[MAX_N + 1][MAX_N + 1];

ui64 compute_lcs(string x, string y) {
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < x.length(); ++i) {
        for (int j = 0; j < y.length(); ++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]);
        }
    }

    return dp[x.length()][y.length()];
}

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

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

    return 0;
}

C++: #pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int q; cin >> q;

    REP(_, q) {
        string x, y; cin >> x >> y;

        vector<vi> dp(x.size() + 1, vi(y.size() + 1, 0));

        REP(i, x.size()) REP(j, y.size()) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + int(x[i] == y[j]));
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j+1]);
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i+1][j]);
        }

        print(dp[x.size()][y.size()]);
    }

}