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 <string>
#include <iostream>
using namespace std;

// ???????????§???????????§?????§??????
int DP[1024][1024] = {};

int main(){
    int N;
    cin >> N;
    for(int c=0; c<N; ++c){
        string X,Y;
        cin >> X >> Y;
        int xlen = (int)X.size();
        int ylen = (int)Y.size();

        for(int i=0;i<=xlen;++i){
          DP[i][0] = 0;
        }
        for(int i=0;i<=ylen;++i){
          DP[0][i] = 0;
        }

        for(int i=1;i<=xlen;++i){
            for(int j=1;j<=ylen;++j){
                if(X[i] == Y[j]){ // 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[xlen][ylen] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int I=0;I<n;I++){
    string a=" ";
    string b=" ";
    string c;
    cin >> c;
    a+=c;
    cin >> c;
    b+=c;
  
    int dp[a.size()][b.size()];
    for(int i=0;i<a.size();i++){
      for(int j=0;j<b.size();j++){
	if(i==0||j==0)dp[i][j]=0;
	else if(a[i]==b[j])dp[i][j]=dp[i-1][j-1]+1;
	else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
      }
    }
    cout << dp[a.size()-1][b.size()-1] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int dp[1005][1005];

int main()
{
	ios_base::sync_with_stdio(0);
	int N; cin >> N;
	while (N-- ){
		memset (dp, 0, sizeof (dp ) );
		string s = "", t = "";
		cin >> s >> t;
		int n = s.length();
		int m = t.length();
		
		dp[0][0] = (s[0] == t[0] );

		for (int i = 1; i < n; i++ )
			if (s[i] == t[0] )
				dp[i][0] = 1;
			else
				dp[i][0] = max (dp[i][0], dp[i-1][0] );

		for (int j = 1; j < m; j++ )
			if (s[0] == t[j] )
				dp[0][j] = 1;
			else
				dp[0][j] = max (dp[0][j], dp[0][j-1] );

		for (int i = 1; i < n; i++ ){
			for (int j = 1; j < m; j++ ){
				dp[i][j] = max (dp[i][j], dp[i-1][j-1] + (s[i] == t[j] ) );
				dp[i][j] = max (dp[i][j], dp[i-1][j] );
				dp[i][j] = max (dp[i][j], dp[i][j-1] );
			} // end for
		} // end for
#if (DEBUG )
		rep (i, n ){
			rep (j, m ){
				printf ("%3d", dp[i][j] );
			} // end rep
			printf ("\n" );
		} // end rep
#endif		
		int res = 0;
		rep (i, n ) rep (j, m ) res = max (res, dp[i][j] ); 		
		cout << res << endl;
	} // end loop
		
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    rep(i,n){
        string s,t;cin >>s >>t;
        vvl dp(s.size()+1,vl(t.size()+1,0));
        rep(j,s.size()){
            rep(k,t.size()){
                if(s[j]==t[k]){
                    dp[j+1][k+1]=dp[j][k]+1;
                }
                else{
                    dp[j+1][k+1]=max(dp[j][k+1],dp[j+1][k]);
                }
            }
        }
        cout << dp[s.size()][t.size()] <<endl;
    }
}

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

int LCS(string s1, string s2){
    int l1 = s1.size();
    int l2 = s2.size();

    int dp[l1 + 1][l2 + 1];
    for(int i = 0; i < l1 + 1; i++){
        for(int j = 0; j < l2 + 1; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
            }
            else if(s1[i - 1] == s2[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    return dp[l1][l2];
}

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

    for(int i = 0; i < n; i++){
        string s1, s2;
        cin >> s1;
        cin >> s2;
        printf("%d\n", LCS(s1, s2));
    }


    return 0;
}

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

using namespace std;

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

int main() {
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        string S, T;
        cin >> S >> T;
        int N = S.length(), M = T.length();
        S.insert(S.begin(), '$');
        T.insert(T.begin(), '$');

        auto dp = Vec<int>(N + 1, M + 1, 0);
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if (S[i] == T[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
        cout << dp[N][M] << endl;
    }
    return 0;
}