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 <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

int dp[1002][1002];

int main(){
	int n;
	cin >> n;
	int x, y;
	string X, Y;
	r(k, n){
		cin >> X >> Y;
		x = X.size();
		y = Y.size();
		X = ' ' + X;
		Y = ' ' + Y;

		r(i, x+1)
			r(j, y+1)
				dp[i][j] = 0;

		for (int i = 1; i <= x; i++) {
			for (int j = 1; j <= y; j++) {
				if (X[i] == Y[j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}

		cout << dp[x][y] << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int q;cin>>q;
    vstr x(q),y(q);
    rep(i,q)cin>>x[i]>>y[i];
    vin ans(q);
    rep(i,q){
        int sx=x[i].size();
        int sy=y[i].size();
        vvin dp(sx+1,vin(sy+1,0));
        rep(j,sx){
            rep(k,sy){
                if(x[i][j]==y[i][k])dp[j+1][k+1]=max(dp[j][k]+1,max(dp[j+1][k],dp[j][k+1]));
                else dp[j+1][k+1]=max(dp[j+1][k],dp[j][k+1]);
            }
        }
        ans[i]=dp[sx][sy];
    }
    rep(i,q)cout<<ans[i]<<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 <bits/stdc++.h>

#define NIL -1
#define INF 1000000001

using namespace std;


int main(){
    int num_dataset;
    char temp[1000];
    scanf("%d",&num_dataset);
    int numSubSeq[1001][1001];
    for(int i = 0;i < 1001;i++) numSubSeq[i][0] = 0; 
    for(int i = 0;i < 1001;i++) numSubSeq[0][i] = 0;

    for(int i = 0;i < num_dataset;i++){
        scanf("%s",temp);
        string str_A = temp;
        int size_A = (int)str_A.size();
        str_A = ' ' + str_A;
  
        scanf("%s",temp);
        string str_B = temp;
        int size_B = (int)str_B.size();
        str_B = ' ' + str_B;
     
        for(int j = 1;j <= size_A;j++){
            for(int k = 1;k <= size_B;k++){    
                if(str_A[j] == str_B[k]){
                    numSubSeq[j][k] = numSubSeq[j-1][k-1] + 1;
                }else{
                    numSubSeq[j][k] = max(numSubSeq[j-1][k],numSubSeq[j][k-1]);
                }
            }
        }
        printf("%d\n",numSubSeq[size_A][size_B]);
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
 
int lcs(string X, string Y) {
int max = 0;
int n = X.size();
int m = Y.size();
int dp[1000+1][1000+1];
 
X = ' '+X;
Y = ' '+Y;
 
for(int i = 1;i <= n; i++)
dp[i][0] = 0;
 
for(int i = 1; i <= m; i++)
dp[0][i] = 0;
 
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; 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;
cin >> N;
 
string X, Y;
for (int i = 0; i < N; i++) {
cin >> X >> Y;
 
cout << lcs(X, Y) << endl;
}
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] != '\0')
      a++;
    else
      sw = 1;
  }
  
  sw = 0;
  
  while(sw == 0){
    if(B[b] != '\0')
      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 <vector>
#include <algorithm>

using namespace std;

int lcs(const string & a, const string & b)
{
    vector<vector<int> > dp(a.size(), vector<int>(b.size()));

    for (size_t i = 0; i < dp.size(); ++i) {
        for (size_t j = 0; j < dp[0].size(); ++j) {
            if (a.at(i) == b.at(j)) {
                dp[i][j] = ((i == 0 || j == 0) ? 0 : dp[i - 1][j - 1]) + 1;
            } else {
                dp[i][j] = max(i == 0 ? 0 : dp[i - 1][j],
                               j == 0 ? 0 : dp[i][j - 1]);
            }
        }
    }

    return dp[a.length() - 1][b.length() - 1];
}

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

    return 0;
}

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 = 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][j-1], c[i-1][j]);
            }
            maxl = max(maxl, c[i][j]);
        } 
    } 
    return maxl;
}

int main()
{
    string x,y;
    int q;
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        int ans = lcs(x, y);
        cout<<ans<<endl;
    }
    return 0;
}