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<vector>
#include<string>
#include<algorithm>
using namespace std;
string s1,s2;
int memo[1001][1001];

int solve(int l1,int l2){
  if(l1 < 0 or l2 < 0)return 0;
  if(memo[l1][l2] >= 0)return memo[l1][l2];
  //cout << s1[l1] << s2[l2] << endl;
  if(s1[l1] == s2[l2]){
    return memo[l1][l2] = solve(l1 - 1,l2 - 1) + 1;
  }
  return memo[l1][l2] = max(solve(l1,l2-1), solve(l1-1,l2));
}
int main(){
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    fill(memo[0],memo[100],-1);
    cin >> s1 ;
    cin >> s2;
    cout << solve(s1.length(),s2.length()) - 1 << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int cal(string x, string y)
{
  int n1 = x.size(), n2 = y.size();
  vector<vector<int> > dp(n1 + 5, vector<int>(n2 + 5, 0));
  for (int i = 0; i < n1; ++i) {
    for (int j = 0; j < n2; ++j) {
      if (x[i] == y[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]);
      }
    }
  }
  return dp[n1][n2];
}

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  for (int i = 0; i < n; ++i) {
    string x, y;
    cin >> x >> y;
    int len = cal(x, y);
    fprintf(stdout, "%d\n", len);
  }
  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()<<endl;
		}
		return 0;
	}

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)
{
    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]);
        }
    }
    return dp[X.size()][Y.size()];
}

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 <stdio.h>

int judge(char A[], char B[]){
  int a=0, b=0, sw=0, ans=0;
  int i, j;
  int C[1001][1001];
  
  while(sw == 0){
    if(A[a] != EOF)
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw = 0){
    if(B[b] != EOF)
      b++;
    else
      sw = 1;
  }
  
  for(i=1; i<a+1; i++)
    C[i][0] = 0;
  for(i=1; i<b+1; i++)
    C[0][i] = 0;
  
  for(i=1; i<a+1; i++){
    for(j=1; j<b+1; j++){
      if(A[i-1] == B[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(ans < C[i][j])
        ans = C[i][j];
    }
  }
  
  return ans;
}

int main(){
  char A[1000], B[1000];
  int n, i;
  
  scanf("%d", &n);
  
  for(i=0; i<n; i++){
    scanf("%s", &A);
    scanf("%s", &B);
    printf("%d\n", judge(A, B));
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
const int N_MAX = 1005;
char res[N_MAX][N_MAX];

int lcs(string X, string Y){
	int xLen = X.size();
	int yLen = Y.size();
	int maxRes=0;
	X=' '+X;
	Y=' '+Y;
	for(int i=1;i<=xLen;i++){
		for(int j=1;j<=yLen;j++){
			if(X[i]==Y[j]){
				res[i][j] = res[i-1][j-1]+1;
			}else if(res[i][j-1]>=res[i-1][j]){
				res[i][j] = res[i][j-1];
			}else{
				res[i][j] = res[i-1][j];
			}
			maxRes = (res[i][j]>maxRes)?res[i][j]:maxRes;
		}
	}
	return maxRes;
}

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

C++: 
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int lcs[1001][1001];

int seek_lcs_body(const char* s1, int pos1, const char* s2, int pos2)
{
	if(s1[pos1] == s2[pos2]){
		return lcs[pos1][pos2] + 1;
	}
	else if(s1[pos1] != s2[pos2]){
		int max = lcs[pos1+1][pos2] > lcs[pos1][pos2+1]? lcs[pos1+1][pos2] : lcs[pos1][pos2+1];
		return max;
	}
	return 0;
}

int seek_lcs(const char* s1, const char* s2)
{
	int sz1=strlen(s1), sz2=strlen(s2);
	for(int i=1; i<=sz1; ++i){
		for (int j=1; j<=sz2; ++j){
			lcs[i][j] = seek_lcs_body(s1, i-1, s2, j-1);
		}
	}
	cout << lcs[sz1][sz2] << endl;
	return 0;
}

int main(){
	int q;
	scanf("%d",&q);

	for(int i=0; i<1001; ++i){
		lcs[i][0] = 0;
		lcs[0][i] = 0;
	}

	for(int i=0; i<q; ++i){
		string s1, s2;
		cin >> s1;
		cin >> s2;
		seek_lcs(s1.c_str(), s2.c_str());
	}
	return 0;
}

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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0, p = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			mat[i][0] = x[i] == y[0] ? true : false;
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			mat[0][i] = x[0] == y[i] ? true : false;
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				mat[i][j] = x[i] == y[j] ? true : false;
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
				if (a[i][j] > p) p = a[i][j];
			}
		}
		if (a[x.length() - 1][0] > p) p = a[x.length() - 1][0];
		if (a[0][y.length() - 1] > p) p = a[0][y.length() - 1];
		cout << p << endl;
	}


	return 0;
}

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;
  }
}