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>
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>
using namespace std;
long long dp[1005][1005];
int main()
{
	char X[1005],Y[1005];
	int n,x,y; cin>>n;
	while(n--){
		scanf("%s%s",X,Y);
		x = strlen(X);
		y = strlen(Y);
		for(int i=0;i<=max(x,y);i++)
			dp[0][i] = dp[i][0] = 0;
		for(int i=1;i<=x;i++)
			for(int j=1;j<=y;j++)
				if(X[i-1]==Y[j-1]) dp[i][j] = dp[i-1][j-1]+1;
				else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		printf("%d\n",dp[x][y]);
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
????????
int LCS(char *X, char *Y){
????int i,j,m,n,c[1001][1001];
????m = strlen(X);
????n = strlen(Y);
????????????
????for(i=0; i<m; i++){
????????c[i][0] = 0;
????}
????for(j=0; j<n; j++){
????????c[0][j] = 0;
????}
????????
????for(i=1;i<m+1;i++){
????????for(j=1;j<n+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];
????????}
????}
????return c[i-1][j-1];
}
????????
int main(){
????int i, q;
????char X[1001], Y[1001];
????????????
????scanf("%d", &q);
????for(i=0; i<q; i++){
????????scanf("%s", X);
????????scanf("%s", Y);
????????printf("%d\n", LCS(X, Y));
????????
????}
????return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int NN;
string s1, s2;
int dp[1001][1001];

int run(){
	int N1 = s1.length();
	int N2 = s2.length();

	rep(i1, N1+1)
	rep(i2, N2+1){
		if(i1 == 0 || i2 == 0) dp[i1][i2] = 0;
		else{
			if(s1[i1-1] == s2[i2-1]) dp[i1][i2] = dp[i1-1][i2-1] + 1;
			else dp[i1][i2] = max(dp[i1-1][i2], dp[i1][i2-1]);
		}
	}
	return dp[N1][N2];
}

int main() {
	cin >> NN;
	rep(i, NN){
		cin >> s1;
		cin >> s2;
		cout << run() << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>

using namespace std;

typedef long long ll;

int lcs(string X, string Y){
  int x = X.size();
  int y = Y.size();

  int d[y+1][x+1];
  memset(d, 0, sizeof(d));

  for(int i = 1; i <= y; i++){
    char a = Y[i-1];

    for(int j = 1; j <= x; j++){
      char b = X[j-1];

      if(a == b){
        d[i][j] = max(d[i][j], d[i-1][j-1] + 1);
      }else{
        d[i][j] = max(d[i-1][j], d[i][j-1]);
      }
    }
  }

  return d[y][x];
}

int main(){
  int n;
  string x, y;
  cin >> n;

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

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 rep(i,a) for(i=0;i<a;i++)
using namespace std;

int main(void){
    int i,j,q;
    string x,y;
    vector<vector<int> > lcs;
    cin >> q;
    while(q--){
        cin >> x >> y;
        int M = x.size();
        int N = y.size();
        lcs.resize(M+1);
        rep(i,M+1){
            lcs[i].resize(N+1);
        }
        rep(i,M){
            rep(j,N){
                if(x[i] == y[j])
                    lcs[i+1][j+1] = lcs[i][j]+1;
                else
                    lcs[i+1][j+1] = max(lcs[i+1][j],lcs[i][j+1]);
            }
        }
        cout << lcs[M][N] << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int q,i,j,k,l1,l2,m,n;
    string X,Y;
    cin>>q;
    for(i=0; i<q; i++)
    {
        cin>>X>>Y;
        l1=X.length()+1;
        l2=Y.length()+1;
        int arr[l2][l1];
        for(k=0; k<l1; k++)
        {
            arr[0][k]=0;
        }
        for(k=0; k<l2; k++)
        {
            arr[k][0]=0;
        }
        for(k=1; k<l2; k++)
        {
            for(j=1; j<l1; j++)
            {
                if(Y[k-1]==X[j-1])
                {
                    arr[k][j]=1+arr[k-1][j-1];
                }
                else
                {
                    m=arr[k-1][j];
                    n=arr[k][j-1];
                    arr[k][j]=max(m,n);
                }
            }
        }
        cout<<arr[l2-1][l1-1]<<endl;
    }
}