Go: package main

import "fmt"

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

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

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

int main(){
  int Q; cin >> Q;
  for(int i = 0; i < Q; i++){
    string s, t; cin >> s >> t;
    int N = s.size(), M = t.size();
    vector<vector<int> > dp(N + 1, vector<int> (M + 1, 0));
    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]);
        }
      }
    }
    cout << dp[N][M] << endl;
  }
}

C++: #include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int dp[1010][1010];
int main(){
    //cout<<"Yes"<<endl;
    int n;
    cin>>n;
    rep(k,n){
        //cout<<"aaa"<<endl;
        string s,t;
        cin>>s>>t;
        rep(i,1010) rep(j,1010) dp[i][j]=0;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<t.size();j++){
                if(s[i]==t[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[s.size()][t.size()]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstring>
using namespace std;
int dp[1000][1000];
string s1,s2;
int len1,len2;

int Str(){
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=len1;i++)
		for(int j=1;j<=len2;j++){
			if(s1[i]==s2[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[len1][len2];
	}
	
	int main(){
		int n;
		cin>>n;
		while(n--){
			cin>>s1>>s2;
			len1=s1.size();
			len2=s2.size();
			s1=' '+s1;
			s2=' '+s2;
			cout<<Str()<< '\n';
		}
		return 0;
	}

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

int lcs(string a,string b){
    int la=a.size();
    int lb=b.size();

    int array[la+1][lb+1];
    for(int i=0;i<=la;i++){
        array[i][0]=0;
    }
    for(int i=0;i<=lb;i++){
        array[0][i]=0;
    }
    for(int i=1;i<=lb;i++){
        for(int j=1;j<=la;j++){
            if(a[j-1]==b[i-1]){
                array[j][i]=array[j-1][i-1]+1;
            }
            else{
                if(array[j-1][i]>array[j][i-1]){
                    array[j][i]=array[j-1][i];
                }
                else{
                    array[j][i]=array[j][i-1];
                }
            }
        }
    }
    return array[la][lb];
}

int main(){
    string a,b;
    int d;
    cin>>d;
    int c[d];
    for(int i=0;i<d;i++){
        cin>>a>>b;
        c[i]=lcs(a,b);  
    }
    for(int i=0;i<d;i++){
        cout<<c[i]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
int main()
{
  int n;
  int an[1000];
  int l=0;
  std::cin>>n;
  std::string x;
  std::string y;
  int ans[1000][1000];
  int j,k;
  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++){
	ans[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  ans[j][k]=ans[j-1][k-1]+1;
	}else{
	  if(ans[j][k-1]>ans[j-1][k]){
	    ans[j][k]=ans[j][k-1];
	  }else{
	    ans[j][k]=ans[j-1][k];
	  }
	}
      }
    }
    std::cout<<ans[x.size()-1][y.size()-1]<<'\n';  
  }
  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(500, vector<int>(10500, -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 <cstring> 
using namespace std;
int c[1001][1001];

int lcs(string x, string y)
{
    int maxl = 0;
    int m = x.length(), n = y.length();
 
    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 = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (x[i] == y[j])
            { 
                if(i==0 || j==0) c[i][j] = 1;
                else c[i][j] = c[i-1][j-1] + 1; 
            }else
            {
                if(i==0 || j==0) c[i][j] = 0;
                else c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    return maxl;
}

int main()
{
    
    //freopen("in1.txt","r",stdin);
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
 
int main(){
  int c[1001][1001];
  string x,y;
  int n; cin >> n;
  while(n>0){
    n--;
    
    //文字列の入力
    cin >> x;
    cin >> y;

    //入力した文字列の長さをもとめる
    int lenx = x.size();
    int leny = y.size();
 
    //初期条件
    for(int i = 1; i <= lenx; i++){
      c[i][0] = 0;
    }
    
    //初期条件
    for(int j = 1; j <= leny; j++){
      c[0][j] = 0;
    }


    //LCS
    for(int i = 1; i <= lenx; i++){
      for(int j = 1; j <= leny; j++){
	//着目している文字が等しいとき
    if(x[i-1]==y[j-1]){
      c[i][j] = c[i-1][j-1] + 1;
      //着目している文字が等しくないときは
      //表の左と上の小さいほうを出力
    }else if(c[i-1][j] >= c[i][j-1]){
      c[i][j] = c[i-1][j];
    }else{
      c[i][j] = c[i][j-1];
    }
      }
    }
    
    //出力
    cout << c[lenx][leny] << endl;
  }
  return 0;
}

C++: /*
 * ALDS1_10_C.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<cstring>
#include<algorithm>

int dp[1001][1001];
bool dpR[1001][1001];

int lcm(char* X, char* Y, int nx, int ny) {
	dp[1][1] = (X[0] == Y[0]);
	for(int i=1; i<=nx; i++) {
		for(int j=1; j<=ny; j++) {
			dp[i][j] = (X[i-1]==Y[j-1]) + dp[i-1][j-1];
			dp[i][j] = std::max(dp[i-1][j], dp[i][j]);
			dp[i][j] = std::max(dp[i][j-1], dp[i][j]);
		}
	}
	return dp[nx][ny];
}

int lcmRec(char* X, char* Y, int nx, int ny) {
	if(nx <=0 || ny <= 0) return 0;
	if(!dpR[nx][ny]) {
		dpR[nx][ny] = 1;
		dp[nx][ny] = lcmRec(X, Y, nx-1, ny-1) + (X[nx-1]==Y[ny-1]);
		dp[nx][ny] = std::max(lcmRec(X, Y, nx-1, ny), dp[nx][ny]);
		dp[nx][ny] = std::max(lcmRec(X, Y, nx, ny-1), dp[nx][ny]);
	}
	return dp[nx][ny];
}

int main() {
	int q;
	scanf("%d", &q);
	char X[1001];
	char Y[1001];
	while(q--) {
		scanf("%s", X);
		scanf("%s", Y);
		int nx = (int)strlen(X);
		int ny = (int)strlen(Y);
		//printf("%d\n", lcm(X, Y, nx, ny));
		printf("%d\n", lcmRec(X, Y, nx, ny));
	}
}