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<algorithm>
using namespace std;
int dp[111][111];
int lcs(string x,string y){
	for(int i=0;i<12321;i++)dp[i/111][i%111]=0;
	for(int i=0;i<=y.size();i++){
		for(int j=0;j<=x.size();j++){
			if(i==0 || j==0){dp[i][j]=0;}
			else if(x[j]==y[i]){dp[i][j]=dp[i-1][j-1]+1;}
			else{dp[i][j]=max(dp[i][j-1],dp[i-1][j]);}
		}
	}
	int MAXN=0;
	for(int i=0;i<=y.size();i++){
		for(int j=0;j<=x.size();j++){
			MAXN=max(MAXN,dp[i][j]);
		}
	}
	return MAXN;
}
int main(){
	int n;string S,T;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>S>>T;cout<<lcs(S,T)<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
int main(){
  int k,m,n,i,j,q,c[1001][1001],max=0;
  char X[1000],Y[1000];
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%s %s",X,Y);
    m=strlen(X);
    n=strlen(Y);
    for(j=m;j>=1;j--){
      X[j]=X[j-1];
    }
    X[0]=' ';
    X[m+1]='\0';
    for(j=n;j>=1;j--){
      Y[j]=Y[j-1];
    }
    Y[0]=' ';
    Y[m+1]='\0';
    for(j=1;j<=m;j++)c[j][0]=0;
    for(j=1;j<=n;j++)c[0][j]=0;
    for(j=1;j<=m;j++){
      for(k=1;k<=n;k++){
	if(X[j]==Y[k])c[j][k]=c[j-1][k-1]+1;
	else{
	  if(c[j][k-1]>c[j-1][k])c[j][k]=c[j][k-1];
	  else c[j][k]=c[j-1][k];
	}
	if(max<c[j][k])max=c[j][k];
      }
    }
    printf("%d\n",max);
    max=0;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int lcs(string X, string Y) {
  int memo[1010][1010];
  // 初期化
  for (int i = 0; i < X.size(); i++) {
    memo[i][0] = 0;
  }
  for (int i = 0; i < Y.size(); i++) {
    memo[0][i] = 0;
  }
  int maxl = 0;
  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (X[i] == Y[j]) {
        memo[i][j] = memo[i-1][j-1] + 1;
      } else {
        memo[i][j] = max(memo[i-1][j], memo[i][j-1]);
      }
      maxl = max(maxl, memo[i][j]);
    }
  }
  return maxl;
}

int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string X, Y;
    cin >> X >> Y;
    cout << lcs(X, Y) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int lcs(string X,string Y){
	int x=X.size(),y=Y.size();
	X = ' '+X;
	Y= ' '+Y;
	int c[1000+10][1000+10];
	for(int i=0;i<1010;i++){
		c[i][0]=0;
		c[0][i]=0;
	}
	for(int i=1;i<=x;i++){
		for(int j=1;j<=y;j++){
			if(X[i]==Y[j]){
				c[i][j]=c[i-1][j-1]+1;
			}
			else{
				c[i][j]=max(c[i][j-1],c[i-1][j]);
			}
		}
	}
	return c[x][y];
}

int main() {
	int n;
	string s1,s2;
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>s1>>s2;
	cout<< lcs(s1,s2)<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int num;
string X;
string Y;
char c1,c2;
int longest;
int L[1010][1010];
int main()
{
    cin>>num;
    for(int i=0;i<num;i++)
    {
        longest=0;
        cin>>X>>Y;
        for(int m=0;m<=X.size();m++)
            for(int n=0;n<=Y.size();n++)
            {
                if(m<=0||n<=0)
                    L[m][n]=0;
                else if(X[m-1]==Y[n-1])
                    L[m][n]=1+L[m-1][n-1];
                else
                    L[m][n]=max(L[m][n-1],L[m-1][n]);
            }
        for(int a=0;a<=X.size();a++)
            for(int b=0;b<=Y.size();b++)
            {
                if(L[a][b]>longest)
                    longest=L[a][b];
            }
        cout<<longest<<endl;
    }
    return 0;
}

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

static const int N = 100;

int main(){
	int n, p[N+1], m[N+1][N+1];
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> p[i-1] >> p[i];
	}

	for (int i=1; i<=n; i++) m[i][i] = 0;
	for (int l=2; l <= n; l++){
		for (int i=1; i<=n-l+1; i++){
			int j = i + l - 1;
			m[i][j] = 1 << 21;
			for (int k = i; k<= j - 1; k++){
				m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

	return 0;
}

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

int main(){
  int q;
  cin >> q;
  for(int m=0; m<q; m++){
    string wordx, wordy;
    cin >> wordx >> wordy;
    int L[1010][1010]={0};
    
    for(int j=0; j<wordy.size(); j++){
      for(int i=0; i<wordx.size(); i++){
	if(wordx[i]==wordy[j]){
	  L[i+1][j+1] = 1+L[i][j];
	}
	else{
	  L[i+1][j+1] = max(L[i+1][j], L[i][j+1]);
	}
      }
    }
    cout << L[wordx.size()][wordy.size()] << endl;
    
    
  }
}

C++: #include <stdio.h>
#include <string.h>

#define NMAX 1000
#define max(a, b) (a > b ? a : b)

int c[NMAX + 10][NMAX + 10]; // 1-origin

int lcs(char *x, char *y) {
    int m = strlen(x);
    int n = strlen(y);
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (x[i - 1] == y[j - 1]) // 0-origin
                c[i][j] = 1 + c[i - 1][j - 1];
            else
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
        }
    }
    return c[m][n];
}

int main() {
    // init
    for (int i = 1; i <= NMAX; i++) {
        c[0][i] = 0;
        c[i][0] = 0;
    }
    int q;
    scanf("%d", &q);
    char x[NMAX + 10], y[NMAX + 10]; // 0-origin
    for (int i = 0; i < q; i++) {
        scanf("%s %s", x, y);
        printf("%d\n", lcs(x, y));
    }
    return 0;
}