Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	for i := 0; i < num; i++ {
		sc.Scan()
		in1 := sc.Text()
		sc.Scan()
		in2 := sc.Text()
		countMax(in1, in2)
	}
}

func countMax(in1 string, in2 string) {
	counta := make([][]int, len(in2)+1)
	for i := 0; i < len(in2)+1; i++ {
		for j := 0; j < len(in1)+1; j++ {
			counta[i] = append(counta[i], 0)
		}
	}

	// fmt.Println(counta)
	for a1, v1 := range in1 {
		i1 := a1 + 1
		for a2, v2 := range in2 {
			i2 := a2 + 1
			// fmt.Printf("1:%v 2:%v\n", i1, i2)
			if v1 == v2 {
				counta[i2][i1] = counta[i2-1][i1-1] + 1
				continue
			}
			val := counta[i2-1][i1]
			if val < counta[i2][i1-1] {
				val = counta[i2][i1-1]
			}

			counta[i2][i1] = val
		}
	}
	fmt.Println(counta[len(in2)][len(in1)])
}

C++: #include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define clr(a,v) memset((a),(v),sizeof(a))

int q;
int dp[1000][1000];
std::string s, t;

int rec( int i, int j )
{
  int &ret = dp[i][j];

  if( ~ret )
    return ret;

  if( i == s.size() || j == t.size() )
    return 0;

  ret = 0;

  if( s[i] == t[j] )
    ret = std::max( ret, rec( i+1, j+1 )+1 );

  ret = std::max( { ret, rec( i+1, j ), rec( i, j+1 ) } );

  return ret;
}

int main()
{
  scanf( "%d", &q );
  while( q-- )
  {
    std::cin >> s >> t;

    clr( dp, -1 );

    std::cout << rec( 0, 0 ) << std::endl;
  }

  return 0;
}

C++: #include<stdio.h>
#include<string.h>
????????
int LCS(char *X, char *Y){
????int i,j,m,n,c[1001][1001];
????m = strlen(X);
????n = strlen(Y);
????????????
????for(i=0; i<m; i++){
????????c[i][0] = 0;
????}
????for(j=0; j<n; j++){
????????c[0][j] = 0;
????}
????????
????for(i=1;i<m+1;i++){
????????for(j=1;j<n+1;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];
????????}
????}
????return c[i-1][j-1];
}
????????
int main(){
??}
????return 0;
}

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

int lcs(string &X, string &Y) {
  int dp[1000 + 1][1000 + 1];
  int max = 0;
  int m = X.size();
  int n = Y.size();
  X = ' ' + X;
  Y = ' ' + Y;

  for (int i = 1; i <= m; i++)
    dp[i][0] = 0;

  for (int i = 1; i <= n; i++)
    dp[0][i] = 0;

  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (X[i] == Y[j])
	dp[i][j] = dp[i-1][j - 1] + 1;
      else if (dp[i - 1][j] >= dp[i][j - 1])
	dp[i][j] = dp[i - 1][j];
      else
	dp[i][j] = dp[i][j - 1];

      if(max < dp[i][j])
	max = dp[i][j];
    }
  }

  return max;
}

int main() {
  int N = 0;
  cin >> N;

  string X, Y;
  for (int i = 0; i < N; i++) {
    cin >> X >> Y;

    cout << lcs(X, Y) << endl;
  }

  return 0;
}

C++: #if 0
?????????X[0]???????????????????????\???????????¨??§???X[1],Y[1]???????????????????????????????????????
#endif

#include <iostream>
#include <string>
using namespace std;

int main(){
	int q;
	cin >> q;
	for(int a=0;a<q;++a){
		string X,Y;
		int L[1000][1000];
		int MAX;
	cin >> X >> Y;
	for(int i=0;i<1000;++i) //???????????\????????????L????????????
		for(int j=0;j<1000;++j)
			L[i][j]=0;

	X+=" "; 
	Y+=" ";
	
	cin >> q;
	for(int j=1;j<X.length()+1;++j)
		for(int k=1;k<Y.length()+1;++k){
			if(X[j]==Y[k])
				L[j][k]=1+L[j-1][k-1];
			else
				L[j][k]=max(L[j-1][k],L[j][k-1]);
			MAX = max(MAX,L[j][k]);
		}
	cout << MAX << endl;
	}
}

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

using namespace std;



int n;
string a, b;



int main(){
  cin >> n;
  while(n != 0){
    n = n -1;
    int longest[1000][1000];
    cin >> a;
    cin >> b;
    a = ' ' + a;
    b = ' ' + b;
    int mm = 0;
    
   
    for(int i = 1; i <= a.size(); ++i){
      for(int j = 1; j <= b.size(); ++j){
        if(j == 0 || i == 0){
          longest[i][j] = 0;
        }
        else if(a[i] == b[j]){
          longest[i][j] = 1 + longest[i-1][j - 1];
        }
        else{
          longest[i][j] = max(longest[i][j-1], longest[i-1][j]);
        }
        mm = max(mm, longest[i-1][j-1]);
      }
    }
    //cout << a[1] << endl;
    cout << mm << endl;
  }
}

C++: #include<bits/stdc++.h>
#define N 1005
using namespace std;
int n,dp[N][N],xlen,ylen;
string x,y;

int main(){
  cin>>n;
  while(n--){
    cin>>x>>y;
    xlen=x.size();
    ylen=y.size();
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=xlen;i++){
      for(int j=1;j<=ylen;j++){
	if(x[i-1]==y[j-1])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
	dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
      }
    }
    cout<<dp[xlen][ylen]<<endl;
  }
  return 0;
}

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

int longestCommonSubsequence(string X, string Y) {
	int DP_memory[1000+1][1000+1]; //0~length??????
	int sizeX = X.length(); //0????????????????????????????????????????????????????????§???
	int sizeY = Y.length(); //???????????£???????????????
	X = " " + X;
	Y = " " + Y;
	for (int i = 0; i <= sizeX; i++)
		DP_memory[i][0] = 0;
	for (int i = 0; i <= sizeY; i++)
		DP_memory[0][i] = 0;

	for (int i = 1; i <= sizeX; i++) {
		for (int j = 1; j <= sizeY; j++) {
			if (X[i] == Y[j])
				DP_memory[i][j] = DP_memory[i - 1][j - 1] + 1;
			else if (DP_memory[i - 1][j] >= DP_memory[i][j - 1])
				DP_memory[i][j] = DP_memory[i - 1][j];
			else
				DP_memory[i][j] = DP_memory[i][j - 1];
		}
	}
	return DP_memory[sizeX][sizeY];
}

int main() {
	string lcsX[1000];
	string lcsY[1000];
	int setNum;

	cin >> setNum;
	for (int i = 0; i < setNum; i++) {
		cin >> lcsX[i];
		cin >> lcsY[i];

		int lcs = longestCommonSubsequence(lcsX[i], lcsY[i]);
		cout << lcs << endl;
	}
	return 0;
}

C++: //
// Created by miyoshi on 2019/05/23.
//

#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 = 0; 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() {
    int number_of_pair;
    string X, Y;

    cin >> number_of_pair;

    for (int i=0; i < number_of_pair; i++){
        cin >> X;
        cin >> Y;
        cout << lcs(X, Y) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>

using namespace std;

int main(){

  int n;
  cin >> n;

  string s[n],t[n];

  for(int i=0;i<n;i++){
    cin >> s[i] >> t[i];
  }

  int a[n];

  for(int k=0;k<n;k++){
    int dp[s[k].size()+1][t[k].size()+1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < s[k].size(); ++i) {
      for (int j = 0; j < t[k].size(); ++j) {
        if (s[k][i] == t[k][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]);
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
      }
    }
    a[k]=dp[s[k].size()][t[k].size()];
  }

  for(int i=0;i<n;i++)cout << a[i] << endl;

}