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>
#include <algorithm>
using namespace std;
static const int MAX = 1001;
int L[MAX][MAX];

int LCS(string s1, string s2)
{
    int m = s1.size();
    int n = s2.size();
    for (int i = 0; i <= m; ++i)
    {
        L[i][0] = 0;
    }
    for (int i = 0; i <= n; ++i)
    {
        L[0][i] = 0;
    }
    for (int i = 1; i <= m; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            if (s1[i-1] == s2[j-1])
            {
                L[i][j] = L[i-1][j-1] + 1;
            }
            else
            {
                L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        }
    }
    return L[m][n];
}

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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string>

#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--)

using namespace std;
int dp[1001][1001];
//?????????????????????
int n;
string x,y;
void solve(){
	cin >> n;
	REP(j,n){
	cin >> x >> y;
	memset(dp,0,1001*1001);
	int xn = x.size();
	int yn = y.size();
	REP(jj,xn+1){
		 REP(ii,yn+1){
			 if(jj <= 0 || ii <= 0){
				 dp[jj][ii] = 0 ;
			 }
			 else if(x[jj-1]==y[ii-1]) {
				 dp[jj][ii] = 1 + dp[jj-1][ii-1];
			 }
			 else{
				 dp[jj][ii] = max ( dp[jj-1][ii], dp[jj][ii-1] );
		   }
			 //cout << '('<<ii<<','<<jj<<')'<<dp[jj][ii]<<endl;
		 }

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


}


int main(){
solve();
}

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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

#define PB push_back
#define SZ(x) ((int)(x).size())

using namespace std;

typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<int> > VVi;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }

int n;
Vs vs, vt;

int main()
{
	cin >> n;
	REP(_i, n)
	{
		string s, t;
		cin >> s >> t;
		vs.PB(s);
		vt.PB(t);
	}

	REP(_i, n)
	{
		string& s = vs[_i];
		string& t = vt[_i];
		
		VVi dp(SZ(s) + 1, Vi(SZ(t) + 1, 0));

		REP(i, SZ(s))
			REP(j, SZ(t))
		{
			chmax(dp[i + 1][j + 1], dp[i][j + 1]);
			chmax(dp[i + 1][j + 1], dp[i + 1][j]);
			if (s[i] == t[j])
				chmax(dp[i + 1][j + 1], dp[i][j] + 1);
		}

		cout << dp[SZ(s)][SZ(t)] << endl;
	}


}

C++: #include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int dp[1001][1001] = {};

int getLCS(string X, string Y)
{
    int m = 0;
    for (int i = 1; i <= X.size(); i++)
    {
        for (int j = 1; j <= Y.size(); j++)
        {
            dp[i][j] = X[i - 1] == Y[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]);
            m = max(m, dp[i][j]);
        }
    }
    return m;
}

int main()
{
    int q;
    string X, Y;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> X >> Y;
        cout << getLCS(X, Y) << "\n";
    }
    return 0;
}

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

using namespace std;
int n;

int main(void){
    // Your code here!
    string S, T;
    int dp[1001][1001];
    cin >> n;
    for(int c = 0; c < n; c++){
        cin >> S >> T;
        
        for(int i = 0; i <= S.size(); i++){
            dp[i][0] = 0;
        }
        for(int j = 0; j <= T.size(); j++){
            dp[0][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] = max({dp[i][j] + 1, dp[i][j+1], dp[i+1][j]});
                else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
        
        cout << dp[S.size()][T.size()] << endl;
    }
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[1001][1001];
  
  while (flag == 0)
  {
    if (x[xn] >= 97 && x[xn] <= 122)
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] >= 97 && y[yn] <= 122)
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 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];
      }
      if (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}

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

using namespace std;

int m[1500][1500];
int main(){
  int n;
  cin>>n;
  char A[1500];
  char B[1500];
  for(int i=0;i<n;i++){
    cin>>A;
    cin>>B;
    int x;
    int y;
    for(x=0;A[x]!='\0';x++){
      for(y=0;B[y]!='\0';y++){
	if(A[x]==B[y]){
	  m[x+1][y+1]=m[x][y]+1;
	}
	else {
	  if(m[x][y+1]>m[x+1][y]){
	    m[x+1][y+1]=m[x][y+1];
	  }
	  else m[x+1][y+1]=m[x+1][y];
	}
      }
    }
    cout<<m[x][y]<<endl;

  }

  
  return 0;
}

C++: // ALDS1_10_C.cpp
// Dynamic Programming - Longest Common Subsequence

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

int LCS(string s, string t)
{
    int res = 0;
    if (s.empty() || t.empty())
        return res;
    int s_len = s.size();
    int t_len = t.size();
    int len = min(s_len, t_len);
//    int lcs[s_len][t_len];
    vector<vector<int>> lcs(s_len, vector<int>(t_len));
    bool found = false;
    for (int i = 0; i < s_len; i++) {
        if (s[i] == t[0] || found) {
            lcs[i][0] = 1;
            found = true;
        }
    }
    found = false;
    for (int j = 0; j < t_len; j++) {
        if (s[0] == t[j] || found) {
            lcs[0][j] = 1;
            found = true;
        }
    }
    for (int i = 1; i < s_len; i++) {
        for (int j = 1; j < t_len; j++) {
            if (s[i] == t[j]) {
                lcs[i][j] = 1 + lcs[i-1][j-1];
            }
            else {
                lcs[i][j] = max(lcs[i-1][j], lcs[i][j-1]);
            }
        }
    }
    return lcs[s_len - 1][t_len - 1];
}

int main()
{
    int n;
    cin >> n;
    string s, t;
    while (n--) {
        cin >> s >> t;
        int res = LCS(s, t);
        cout << res << endl;
    }
    return 0;
}