Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

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

#define MAX 1000

int lcs(string X, string Y) {
    int c[MAX+1][MAX+1];
    int m = X.size();
    int n = Y.size();
    int i, j;
    int maxlen = 0;
    X = " " + X;
    Y = " " + Y;

    for (i = 1 ; i <= m ; i++ ) c[i][0] = 0;
    for (j = 1 ; j <= n ; j++ ) c[0][j] = 0;

    for(i = 1 ; i <= m ; i++ ) {
        for(j = 1 ; j <= n ; j++ ) {
            if (X[i] == Y[j]) {
                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];
            }
            maxlen = max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}

int main (void) {
    int N, i;
    string x, y;
    

    cin >> N;

    for(i = 0 ; i < N ; i++) {
        cin >> x;
        cin >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}

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 = 0; 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 <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
#include <inttypes.h>
int c[1001][1001] = {0};
int LCS(std::string s, std::string t){
    int n, m;
    n = s.size();
    m = t.size();
    int maxlen = 0;
    for(int i = 1; i <= n; i++){
        c[i][0] = 0;
    }
    for(int i = 1; i <= m; i++){
        c[0][i] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i - 1] == t[j - 1]){
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else{
                c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
            }
            maxlen = std::max(maxlen, c[i][j]);
        }
    }
    return maxlen;
}
int main(){
    int N;

    std::cin >> N;
    std::string s1, s2;
    for(int i = 0; i<N; i++){
        std::cin >> s1 >> s2;
       
        std::cout << LCS(s1,s2) << std::endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        string s, t;
        cin >> s >> t;

        int dp[1010][1010];
        for (int i = 0; i < 1010; ++i)
            for (int j = 0; j < 1010; ++j)
                dp[i][j] = 0;

        int n = s.size();
        int m = t.size();

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

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

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

int dp[1000+1][1000+1];

int main() {
    int n; 
    cin >> n;
    while(n--) {
        string s, t; cin >> s >> t;
        int N = s.length();
        int M = t.length();
        dp[0][0] = 0;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < M; j++) {
                if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
                else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            }
        }
        cout << dp[N][M] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>

using namespace std;
int q;
string text;
int ans[160];
int dp[1100][1100];

int main(){
    cin >> q;
    vector<string> texts;

    for(int i=0;i<q*2;i++){
         cin >> text;
         texts.push_back(text);
    }
    for(int k=0;k<q;k++){
        memset(dp, 0, sizeof(dp));
        for(int i=0;i<texts[2*k].size();i++){
            for(int j=0;j<texts[2*k+1].size();j++){
                if(texts[2*k][i]==texts[2*k+1][j]) dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i+1][j], dp[i][j+1]));
                else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
        ans[k]=dp[texts[2*k].size()][texts[2*k+1].size()];
    } 
    for(int i=0;i<q;i++)cout << ans[i] << endl;
}