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++: n=int(input())
ans=[]
for k in range(n):
    s1=input()
    s2=input()
    dp=[[0 for i in range(len(s2)+1)] for j in range(len(s1)+1)]
    for i in range(1,len(s1)+1):
        for j in range(1,len(s2)+1):
            if s1[i-1]==s2[j-1]:
                dp[i][j]=dp[i-1][j-1]+1
            else:
                dp[i][j]=max(dp[i-1][j],dp[i][j-1])


    ans.append(dp[len(s1)][len(s2)])
for a in ans:
    print(a)

C++: #include<iostream>
#include<string>
using namespace std;
int alignment(string s,string t){


	int a[1001][1001]={};
	int n=s.size();
	int m=t.size();
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(s[i]==t[j]){
					a[i+1][j+1]=max(a[i][j]+1,max(a[i+1][j],a[i][j+1]));
				}else{
					a[i+1][j+1]=max(a[i][j],max(a[i+1][j],a[i][j+1]));
				}
			}
		}
	return a[n][m];
}

int main(void){

	int n;
	
	cin >> n;
	for(int i=0;i<n;i++){

		string s;
		string t;
		cin >> s >> t;
		cout << alignment(s,t) <<endl;
	}
	
}

C++: #include <iostream>
#include <string>
using namespace std;
const int LEN = 1005;
string X,Y;
int dp[LEN][LEN];

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		cin >> X >> Y;

		int xn = X.size();
		int yn = Y.size();

		for (int j = 0; j <= xn; ++j)
		{
			dp[j][0] = 0;
		}

		for (int j = 0; j <= yn; ++j)
		{
			dp[0][j] = 0;
		}

		for (int j = 0; j < xn; ++j)
		{
			for (int k = 0; k < yn; ++k)
			{
				if (X[j] == Y[k])
				{
					dp[j+1][k+1] = max(dp[j][k]+1, max(dp[j][k+1], dp[j+1][k]));
				}
				else
				{
					dp[j+1][k+1] = max(dp[j][k+1], dp[j+1][k]);
				}
			}
		}

		cout << dp[xn][yn] << endl;
	}

	
	return 0;
}

C++: #include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const long long mod=1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dp[1005][1005];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);    
int q=0;
cin>>q;
vector<vector<string>> s(q,vector<string>(2));
for(int i=0;i<q;i++)cin>>s.at(i).at(0)>>s.at(i).at(1);
for(int pos=0;pos<q;pos++){
    memset(dp,0,sizeof(dp));
    string a=s.at(pos).at(0),b=s.at(pos).at(1);
    for(int i=0;i<(int)a.size();i++){
        for(int j=0;j<(int)b.size();j++){
            if(a.at(i)==b.at(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[a.size()][b.size()]<<endl;
}

}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int q;
  cin >> q;
  REP(i, q) {
    string X, Y;
    cin >> X >> Y;
    vector<vector<int>> dp(Y.size() + 5, vector<int>(X.size() + 5, 0));
    for (int i = 0; i < Y.size(); i++) {
      for (int j = 0; j < X.size(); j++) {
        if (Y[i] == X[j]) {
          chmax(dp[i + 1][j + 1], dp[i][j] + 1);
          chmax(dp[i + 1][j + 1], dp[i][j + 1]);
          chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        } else {
          chmax(dp[i + 1][j + 1], dp[i][j + 1]);
          chmax(dp[i + 1][j + 1], dp[i + 1][j]);
        }
      }
    }
    cout << dp[Y.size()][X.size()] << 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=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<cstdio>
#include<cstring>
#define _A_ true
using namespace std;
 
int main(){
  int n,AC=0,strA,strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];
 
  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;
strA = strlen(A); 
strB = strlen(B);

    for(int i=0;i<strA;i++){
      for(int j=0;j<strB;j++){
    if(A[i] == B[j]){
      dp[i+1][j+1]=dp[i][j]+1;
    }
    else{
      if(dp[i+1][j] > dp[i][j+1]){
        dp[i+1][j+1]=dp[i+1][j];
      }
      else {
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
      }
    }
    printf("%d\n",dp[strA][strB]);
    AC++;
  }
  delete [] A;
  delete [] B;
 
  return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int n, m;
string s, t;
const int MAX = 1010;

int dp[MAX][MAX];

int rec(int si, int ti) {
    if (dp[si][ti] >= 0) {
        return dp[si][ti];
    }
    int res = 0;
    if (si == n and ti == m) {
        return res;
    }
    else {
        if (s[si] == t[ti]) {
            res = max(res, rec(si + 1, ti + 1) + 1);
        }
        else {
            if (si < n) {
                res = max(res, rec(si + 1, ti));
            }
            if (ti < m) {
                res = max(res, rec(si, ti + 1));
            }
        }
    }
    return (dp[si][ti] = res);
}

void solve() {
    int q;
    cin >> q;
    while (q--) {
        cin >> s >> t;
        n = s.size(), m = t.size();
        fill(dp[0], dp[MAX], -1);
        cout << rec(0, 0) << endl;
    }
}

int main() {
    solve();
}

C++: // longest common subsequence
#include<iostream>
#include<string>
#include<algorithm>
int LCS(std::string, std::string);
int N=1000;
int main(){
  int n;
  std::string str1, str2;
  std::cin >> n;
  for(int i=0; i<n; i++){
    std::cin >> str1 >> str2;
    std::cout << LCS(str1, str2) << std::endl;
  }
  return 0;
}
int LCS(std::string str1, std::string str2){
  int c[N+1][N+1], m=str1.size(), n=str2.size(), maxl=0;
  str1 = ' ' + str1, str2 = ' ' + str2;
  for(int i=1; i<=m; i++) c[i][0] = 0;
  for(int i=1; i<=n; i++) c[0][i] = 0;
  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      if(str1[i] == str2[j]) c[i][j] = c[i-1][j-1] + 1;
      else c[i][j] = std::max(c[i-1][j], c[i][j-1]);
      maxl = std::max(maxl, c[i][j]);
    }
  }
  return 0;
}