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 = 150;
static const int AX = 1000, AY = 1000;
string  X, Y;

int do_dp(int ax,int ay) {

    int dp[AX][AY];



    for (int i = 0; i < ax; i++) {
        if (X[i] == Y[0]) dp[i][0] = 1;
        if (i > 0) dp[i][0] = max(dp[i][0], dp[i - 1][0]);
    }

    for (int j = 0; j < ay; j++) {
        if (X[0] == Y[j]) dp[0][j] = 1;
        if (j > 0) dp[0][j] = max(dp[0][j], dp[0][j - 1]);
    }

    for (int i = 1; i < ax; i++) {
        for (int j = 1; j < ay; 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[ax - 1][ay - 1];
}

int main() {
    string str;
    int q;

    cin >> q;

    int A[N];

    for (int i = 0; i < q; i++) {
        cin >> X;
        cin >> Y;
        //cout << X.size() << " " << Y.size() << '\n';
        A[i] = do_dp(X.size(),Y.size());
    }

    for (int i = 0; i < q; i++) {
        cout << A[i] << '\n';
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

string LCS(string s, string t){
    ll ns = s.size();
    ll nt = t.size();
    vector< vector<ll> > dp(ns+1, vector<ll> (nt+1, 0));
    // initilaize
    rep(i, 0, ns){
        if(s[i] == t[0]) dp[i][0] = 1;
    }
    rep(i, 0, nt){
        if(s[0] == t[i]) dp[0][i] = 1;
    }
    // build DP table
    rep(i, 1, ns){
        rep(j, 1, nt){
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i] == t[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
        }
    }
    // make LCS
    string ret;
    ll i = ns-1, j = nt-1;
    while(i >= 0 && j >= 0){
        if(s[i] == t[j]){
            ret.push_back(s[i]);
            i--; j--;
        }else{
            if(j == 0) i--;
            else if(i == 0) j--;
            else if(dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    return ret;
}

int main(){
    ll Q;
    cin >> Q;
    rep(q, 0, Q){
        string x, y;
        cin >> x >> y;
        cout << LCS(x, y).size() << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <memory>
#include <string>
#include <map>
using namespace std;
#define MAX 1003

char A[MAX];
char B[MAX];

void print(){}
int DP[MAX][MAX];
int dp(int i,int j){
    if(i==0||j==0) return 0;
    if(DP[i][j]!=-1) return DP[i][j];
    if(A[i]==B[j]) return DP[i][j]=dp(i-1,j-1)+1;
    return DP[i][j]=max(dp(i,j-1),dp(i-1,j));
}
void solve(){
    memset(DP,-1,sizeof(DP));

    int tmp;
        scanf("%d",&tmp);
        while(tmp--){
                memset(DP,-1,sizeof(DP));
                scanf("%s%s",A,B);
            printf("%d\n",dp(strlen(A),strlen(B)));
        }

}

int main(){

  //  freopen("in","r",stdin);
    solve();
    return 0;
}

C++: #include<stdio.h>
#include<string.h>
 
#define N 1000
 
char A[N+1],B[N+1];
  

  
int Max(int a,int b){
  if(a>=b) return a;
  else return b;
}
int main(){
  int k,a,i,j,m,n,max,c[N+1][N+1];
  scanf("%d",&a);
  for(k=0;k<a;k++){
    scanf("%s",A);
    scanf("%s",B);
    max=0;
     m=strlen(A);
  n=strlen(B);
  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(A[i-1]==B[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];
      max=Max(max,c[i][j]);
    }
  }
    printf("%d\n",max);
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int N = 1000;
char s[N+1], t[N+1];
int ls, lt;
int q;
int dp[N+1][N+1];
//dp[i][j] = s[0]...s[i+1]??¨t[0]...t[j+1]???LCS
//(1<=i<=ls, 1<=j<=lt)

int main() {
  int i, j, k;
  scanf("%d ", &q);
  for (k=0; k<q; k++) {
    ls = lt = 0;
    memset(s, 0, sizeof(s)), scanf("%s ", s);
    memset(t, 0, sizeof(t)), scanf("%s ", t);
    while (s[ls]) ls++;
    while (t[lt]) lt++;

    memset(dp, 0, sizeof(dp));
    for (i=1; i<=ls; i++)
      for (j=1; j<=lt; j++) {
        if (s[i]==t[j])
          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[ls][lt]);
  }

  return 0;
}

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

using namespace std;

int lcs (string x, string y) {

    int m, n, c[1001][1001], i, j, maxl = 0;

    m = x.size();
    n = y.size();

    x = ' ' + x;
    y= ' ' + y;

    for (i = 0; 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 {
                    c[i][j] = max (c[i - 1][j], c[i][j - 1]);
                }

                maxl = max (maxl, c[i][j]);

            }
    }

    return maxl;

}



int main () {

    int N, i;
    string x, y;

    cin >> N;

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

    }

    return 0;

}