Go: package main

import "fmt"

func initialize_grid(width int,height int)[][]int{
	var grid [][]int
	for i:=0;i<height+1;i++{
		var grid_row  []int
		for j:=0;j<width+1;j++{
			grid_row = append(grid_row,0)
		}
		grid = append(grid,grid_row[:])
	}
	return grid
}

func ma(x int,y int)int{
	if x >= y{
		return x
	}else{
		return y
	}
}

func main()  {
	//Take input
	var num int
	var st1,st2 string
	var string_pairs [][]string
	fmt.Scan(&num)
	for i:=0;i<num;i++{
		var string_pair []string
		fmt.Scan(&st1)
		fmt.Scan(&st2)
		string_pair = append(string_pair,st1,st2)
		string_pairs = append(string_pairs,string_pair)
	}
	//DP
	//initialize grid
	for i:=0;i<num;i++{
		string_1 := string_pairs[i][0]
		string_2 := string_pairs[i][1]

		dp := initialize_grid(len(string_2),len(string_1))

		for j:=1;j<len(string_1)+1;j++{
			for k:=1;k<len(string_2)+1;k++{
				if string_1[j-1] == string_2[k-1]{
					dp[j][k] = dp[j-1][k-1] + 1
				}else{
					dp[j][k] = ma(dp[j-1][k],dp[j][k-1])
				}
			}
		}
		fmt.Println(dp[len(string_1)][len(string_2)])
	}
}

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

static const int N = 1000;
using namespace std;

int LCS(string X,string Y){
  int m,n;
  
  m = X.size();
  n = Y.size();
  
  int dp[N + 1][N + 1] = {0};
  
  X = ' ' + X;
  Y = ' ' + Y;

  for(int i = 1;i <= m;i++){
    for(int j = 1;j <= n;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]);
      }
    }
  }
  
  /*for(int i = 0;i < ax;i++){
    for(int j = 0;j < ay;j++){
      cout << dp[i][j] << " ";
    }
    cout << '\n';
    }*/
  
  return dp[m][n];
}

int main(){
  int q;
  string X,Y;
  
  cin >> q;
  
  for(int i = 0;i < q;i++){
    cin >> X >> Y;
    //cout << X.size() << " " << Y.size() << '\n';
    cout << LCS(X,Y) << '\n';
  }
  
  return 0;
}

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

int solve(std::string &x, std::string &y){
    int c[1001][1001] = {};
    int m = x.length();
    int n = y.length();

    //for(int i = 1; i <= m; ++i) c[i][0] = 0;                                                                                                                                                                                      
    //for(int i = 1; i <= n; ++i) c[0][i] = 0;                                                                                                                                                                                      
    int maxval = 0;
    x = ' ' + x;
    y = ' ' + y;
    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] = std::max(c[i][j - 1], c[i - 1][j]);
            }
            maxval = std::max(maxval, c[i][j]);
        }
    }
    return maxval;
}

int main(){
    int q;
    std::cin >> q;
    for(int i = 0; i < q; ++i){
        std::string x;
        std::string y;
        std::cin >> x;
        std::cin >> y;
        int res = solve(x, y);
        std::cout << res << "\n";
    }
    return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
#define max(a,b) (a>b ? a : b)
#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 1000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int resolve(string S, string T){
  int s = (int)S.size(), t = (int)T.size();
  vector<vector<int>> dp(s+1, vector<int>(t+1, 0));

  for(int i=0; i<s; i++){
    for(int j=0; j<t; 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]);
    }
  }
  return dp[s][t];
}

int main(){
  int N;
  cin >> N;
  rep(i,N){
    string S, T;
    cin >> S >> T;
    cout << resolve(S, T) << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<cstring>
#include<cstdlib>
#define MAX_N 1000

int solve(std::string s,std::string t){
        int dp[MAX_N][MAX_N]={0};
        int n,m;
        n=s.size(),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]=dp[i][j]+1;
                        else
                                dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
                }
        }
        return dp[n][m];
}

int main(){
        int q;
        std::cin>>q;
        for(int i=0;i<q;i++){
                std::string s,t;
                std::cin >> s>>t;
                std::cout<<solve(s,t)<<std::endl;
        }
        return 0;
}

C++: #include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i < n; ++i)
#define max(a, b) a > b ? a : b

int main(void) {
  int n;
  scanf("%d", &n);
  rep(i, n) {
    char x[1500], y[1500], h, w;
    scanf("%s", x);
    scanf("%s", y);
    h = strlen(x), w = strlen(y);
    int dp[h][w], len[w];
    rep(j, h) rep(k, w) dp[j][k] = 0;
    rep(j, w) if(x[0] == y[j]) dp[0][j] = 1;
    len[0] = 0;
    repi(j, w) len[j] = dp[0][j - 1] | len[j - 1];
    repi(j, h) {
      rep(k, w) if(x[j] == y[k]) dp[j][k] = len[k] + 1;
      repi(k, w) len[k] = max(dp[j][k - 1], len[k - 1]);
    }
   /* rep(j, h) {
      rep(k, w) printf("%d ", dp[j][k]);
      printf("\n");
    }*/
    int max = 0;
    rep(j, w) if(max< dp[h - 1][j]) max = dp[h - 1][j];
    printf("%d\n", max);
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int dp[1001][1001];

int Lcs(string X, string Y) {
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 0; i < X.length(); ++i) {
        dp[i][0] = 0;
    }
    for (int i = 0; i < Y.length(); ++i) {
        dp[0][i] = 0;
    }

    int ans = 0;
    for (int i = 1; i < X.length(); ++i) {
        for (int j = 1; j < Y.length(); ++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]);
            }

            ans = max(ans, dp[i][j]);
        }
    }

    return ans;
}

int main() {
    int n;
    cin >> n;

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

    return 0;
}

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

string s, t;
int dp[1001][1001];
int main()
{
    int p;
    cin >> p;
    while(p>0)
    {
        p--;
        cin >> s >> t;
        int n = s.size();
        int m = t.size();
        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 = 0; j < m; j++) {
                if (s[i - 1] == t[i - 1]) {
                    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];
                }
            }
        }
        cout << dp[n][m] << endl;
    }

}