Go: package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
	"sort"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func maxInt(args... int) int{
	sort.Ints(args)
	return args[len(args)-1]
}

func main(){
	buf := make([]byte, 0)
    sc.Buffer(buf, 1000000009)
	var n int 
	fmt.Scan(&n)
	dp := make([][]int, 1003)
	for i:=0; i<1003; i++ {
		dp[i] = make([]int, 1003)
	}
	input_lines := scanStringLine(2*n)
	for i:=0; i<n; i++ {
		S, T := input_lines[2*i], input_lines[2*i+1]
		lenS, lenT := len(S), len(T)
		for i:=1; i<lenS+1; i++ {
			for j:=1; j<lenT+1; j++ {
				if S[i-1] == T[j-1] {
					dp[i][j] = maxInt(dp[i-1][j-1]+1, dp[i-1][j], dp[i][j-1])
				} else {
					dp[i][j] = maxInt(dp[i-1][j], dp[i][j-1])
				}
			}
		}
		fmt.Println(dp[lenS][lenT])
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define len_max 1000


string X;
string Y;
int dp[len_max+1][len_max+1];

int lcs(){
    int m = X.length();
    int n = Y.length();

    X = ' ' + X;//ずらす
    Y = ' ' + Y;
    

    for(int i = 0; i <= n; i++){
        dp[i][0] = 0;
    }

    for(int i = 0; i <= m; i++){
        dp[0][i] = 0;
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(Y[i] == X[j]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    return dp[n][m];

}


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

    int ans[q];

    for(int i = 0; i < q; i++){
        cin >> X >> Y;
        //printf("%d\n", lcs());
        ans[i] = lcs();
    }

    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXL = 1e3+7;
char s1[MAXL];
char s2[MAXL];
int dp[MAXL][MAXL];
int maxLCS(char s1[], char s2[]){
    int l1 = strlen(s1);
    int l2 = strlen(s2);
    int i;
    for(i = 0; i <= l1; i++){
        dp[0][i] = 0;
    }
    for(i = 0; i <= l2; i++){
        dp[i][0] = 0;
    }
    int j;
    for(i = 1; i <= l2; i++){
        for(j = 1; j <= l1; j++){
            int max_k = max(dp[i-1][j], dp[i][j-1]);
            if(s1[j-1] == s2[i-1]) max_k = max(max_k, dp[i-1][j-1]+1);
            else max_k = max(max_k, dp[i-1][j-1]);
            dp[i][j]= max_k;
        }
    }
    return dp[l2][l1];
}
int main(){
//    freopen(".../in.txt", "r", stdin);
    int q;
    scanf("%d", &q);
    for(int i = 0; i < q; i++){
        scanf("%s", s1);
        scanf("%s", s2);
        int q = maxLCS(s1, s2);
        printf("%d\n", q);
    }
    return 0;
}

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

#define MAX_LENGTH 1000
#define NIL -1
using namespace std;
//think easy make easy

int q;//num of datasets
string X;
string Y;
char map[MAX_LENGTH+1][MAX_LENGTH+1];

int findMaxLength(int x,int y){//x:Xの終端.y:Yの終端(0オリジン)
	int val;

	if(x < 0 || y < 0) return 0;

	if(map[x][y] == NIL){
		if(X.at(x) == Y.at(y)){
			val = findMaxLength(x-1,y-1) +1;
		}else{
			val = max(findMaxLength(x-1,y),findMaxLength(x,y-1));
		}
		map[x][y] = val;//メモ
		return val;
	}else return map[x][y];
}

int main(){
	
	scanf("%d",&q);

	for(int i=0;i<q;i++){
		cin >>X; cin >> Y;
		for(int i=0;i<X.size();i++){
			for(int j=0;j<Y.size();j++){
				map[i][j] = NIL;
			}
		}
	
		cout <<findMaxLength(X.size()-1,Y.size()-1) <<endl;
	}

	return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;
int dp[1001][1001];
int lcs(string x,string y){
  int m,n;
  lll ii,jj,kk;
  
  m = x.size();
  n = y.size();
  memset(dp,0,sizeof(dp));
  int maxl = 0;

  for(ii=0;ii<m;ii++){
    for(jj=0;jj<n;jj++){
      if(x[ii] == y[jj]){
        dp[ii+1][jj+1] = dp[ii][jj] + 1;
      }
      else{
        dp[ii+1][jj+1] = max(dp[ii][jj+1],dp[ii+1][jj]);
      }

      maxl = max(maxl,dp[ii+1][jj+1]);
      
    }
  }
  return maxl;
}

int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int q;
  string x,y;

  cin >> q;

  for(ii=0;ii<q;ii++){
    cin >> x >> y;
    cout << lcs(x,y) << 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 <string>
using namespace std;

int preX[1020][55];
int dp[1020];

int main() {
	int q;
	cin >> q;
	for(int t = 0; t < q; t++) {
		string X, Y;
		for(int i = 0; i < 1020; i++) {
			for(int j = 0; j < 55; j++) {
				preX[i][j] = 0;
			}
			dp[i] = 0;
		}
		cin >> X >> Y;
		for(int i = 0; i < X.size(); i++) {
			for(int j = 0; j < 55; j++) {
				preX[i+1][j] = preX[i][j];
			}
			if(i > 0) {
				if('a' <= X[i-1] && X[i-1] <= 'z')
					preX[i+1][X[i-1]-'a'] = i;
				else
					preX[i+1][X[i-1]-'A'] = i;
			}
		}
		for(int i = 0; i < Y.size(); i++) {
			for(int j = (int)X.size()-1; j >= 0; j--) {
				if(Y[i] == X[j])
					for(int k = 0; k < 55; k++)
						dp[j+1] = max(dp[j+1], dp[preX[j+1][k]] + 1);
			}
		}
		int res = 0;
		for(int i = 0; i < 1020; i++)
			res = max(res, dp[i]);
		cout << res << endl;
	}
}

C++: //compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int solve(string x, string y){
	int xl = x.length() - 1;
	int yl = y.length() - 1;
	int dp[1250][1250];
		for(int i=0;i<=xl;i++) dp[i][0] = 0;
		for(int i=1;i<=yl;i++) dp[0][i] = 0;
	if(x == y) return max(xl, yl);
	for(int i=1;i<=xl;i++){
		for(int j=1;j<=yl;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]);
		}
	}
	return dp[xl][yl];
}

int main(){
	int q;
	string x, y;
	int i;
	cin >> q;
	rep(i, q){
		cin >> x >> y;
		cout << solve(x = " " + x, y = " " + y) <<endl;
	}


}