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;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int dp[1010][1010];

int main() {
    int q;
    cin>>q;
    while(q--){
        string s,t;
        cin>>s>>t;
        int n=s.size(),m=t.size();
        rep(i,1010){
            rep(j,1010){
                dp[i][j]=0;
            }
        }
        rep(i,n){
            rep(j,m){
                if(s[i]==t[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]);
            }
        }

        cout<<dp[n][m]<<endl;
    }

    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;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			for (int j = 0; j < y.length(); j++) {
				if (x[i] == y[j]) {
					mat[i][j] = true;
				}
				else {
					mat[i][j] = false;
				}
			}
		}
		for (int i = 0; i < x.length(); i++) {
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
			}
		}
		int p = 0;
		for (int i = 0; i < x.length(); i++) {
			p = a[i][y.length() - 1] > p ? a[i][y.length() - 1] : p;
		}
		for (int i = 0; i < y.length() - 1; i++) {
			p = a[x.length() - 1][i] > p ? a[x.length() - 1][i] : p;
		}
		cout << p << endl;
	}


	return 0;
}

C++: #include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[101][101];
  
  while (flag == 0)
  {
    if (x[xn] != '\0')
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] != '\0')
    {
      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 <string>
#include <algorithm>

using namespace std;

int main(){
    int q;
    scanf("%d", &q);
    while(q--)
    {
        string X, Y;
        cin>>X>>Y;
        int table[X.length() + 1][Y.length() + 1];
        for(int i=0; i<Y.length() + 1; i++) table[0][i] = 0;
        for(int i=1; i<X.length() + 1; i++)
        {
            table[i][0] = 0;
            for(int j=1; j<Y.length() + 1; j++)
            {
                if(X[i-1] == Y[j-1]) table[i][j] = table[i-1][j-1] + 1;
                else table[i][j] = max(table[i-1][j], table[i][j-1]);
            }
        }
        printf("%d\n", table[X.length()][Y.length()]);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

vector<vector<int> > DP(1000,vector<int>(1000));

void init(int n,int m){
    rep(i,n){
        rep(j,m){DP[i][j]=-1;}
    }
}

int LCS(char a[],char b[],int n,int m){
    if(n<0||m<0)return 0;
    if(DP[n][m]!=-1)return DP[n][m];
    if(a[n]==b[m])return DP[n][m]=1+LCS(a,b,n-1,m-1);
    return DP[n][m]=max(LCS(a,b,n-1,m),LCS(a,b,n,m-1));
}

int main(){
    int q;cin>>q;
    char s[1001],t[1001];
    rep(i,q){
        cin>>s>>t;
        int n=strlen(s),m=strlen(t);
        init(n,m);
        int ans=LCS(s,t,n-1,m-1);
        printf("%d\n",ans);
    }
}

C++: #include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


int main() {
	int n;
	cin >> n;
	rep(i, n) {
		string x, y;
		cin >> x >> y;
		int xl = x.length(), yl = y.length();
		vector<vector<int>> com(xl, vector<int>(yl, 0));
		rep(j, xl) {
			rep(k, yl) {
				if (j == 0) {
					if (k == 0) {
						if (x[j] != y[k]) {
							com[j][k] = 0;
						}
						else {
							com[j][k] = 1;
						}
					}
					else {
						if (com[j][k-1] == 1) {
							com[j][k] = 1;
						}
						else {
							if (x[j] != y[k]) {
								com[j][k] = 0;
							}
							else {
								com[j][k] = 1;
							}
						}
					}
				}
				else {
					if (k == 0) {
						if (com[j-1][k] == 1) {
							com[j][k] = 1;
						}
						else {
							if (x[j] == y[k]) {
								com[j][k] = 1;
							}
							else {
								com[j][k] = 0;
							}
						}
					}
					else {
						if (x[j] == y[k]) {
							com[j][k] = com[j - 1][k - 1]+1;
						}
						else {
							com[j][k] = max(com[j][k - 1], com[j - 1][k]);

						}
					}
				}
				//cout << com[j][k] <<" ";
			}
			//cout << x[j]<<endl;
		}
		cout << com[xl - 1][yl - 1] << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }


int main() {
	
	int q;
	cin >> q;
	for(int cnt=0; cnt<q; cnt++){
		string s,t;
		cin >> s >> t;
		vector<vector<int>> dp(s.size()+1,vector<int>(t.size()+1));
		for(int i=0; i<s.size(); i++){
			for(int j=0; j<t.size(); j++){
				if(s.at(i)==t.at(j)) dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
				else  dp.at(i+1).at(j+1) = max( dp.at(i).at(j+1) , dp.at(i+1).at(j) );
			}
		}
		cout << dp.at(s.size()).at(t.size())<<endl;
	}
}

C++: //ALDS1_10_C:Longest Common Subsequence
#include <bits/stdc++.h>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int main(){
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        string X,Y;
        cin >> X >> Y;
        int lcs[1001][1001];
        for(int i=0; i<=X.size(); i++){
            for(int j=0; j<=Y.size(); j++){
                if(i == 0 || j == 0) lcs[i][j] = 0;
                else if(X[i-1] == Y[j-1]) lcs[i][j] = lcs[i-1][j-1] + 1;
                else lcs[i][j] = max(lcs[i][j-1], lcs[i-1][j]);
            }
        }
        cout << lcs[X.size()][Y.size()] << endl;
    }
}