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 <vector>
#include <algorithm>
using namespace std;
#define MAX_SEQ 1000

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

  for(int i=0;i<n;i++) {
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;
    int seq1_len = 0;
    int seq2_len = 0;
    while(seq1[seq1_len] != '\0')
      seq1_len++;
    while(seq2[seq2_len] != '\0')
      seq2_len++;

    /*
    cout << "length" << endl;
    cout << seq1_len << endl;
    cout << seq2_len << endl;
    */

    int lcs[seq1_len+1][seq2_len+1];
    for(int i=0;i<=seq1_len;i++)
      lcs[i][0] = 0;
    for(int i=0;i<=seq2_len;i++)
      lcs[0][i] = 0;

    for(int i=1;i<=seq1_len;i++) {
      for(int j=1;j<=seq2_len;j++) {
        int s1_it = i-1;
        int s2_it = j-1;
        if(seq1[s1_it] == seq2[s2_it]) {
          lcs[i][j] = lcs[i-1][j-1] + 1;
        }
        else {
          lcs[i][j] = max(lcs[i][j-1],lcs[i-1][j]);
        }
      }
    }
    /*
    cout << "lcs[i][j]" << endl;
    for(int i=0;i<=seq1_len;i++) {
      for(int j=0;j<=seq2_len;j++) {
        cout << lcs[i][j] << " ";
      }
      cout << endl;
    }
    */

    cout << lcs[seq1_len][seq2_len] << endl;
  }
}

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

#define MAX_Q 150
#define MAX_LEN 1000
string s, t;
int dp[MAX_LEN+1][MAX_LEN+1];

int align_dp() {
    fill((int*)dp, (int*)(dp+MAX_LEN+1), 0);
    // dp[i][j] := i-1番目、j-1番目までの文字で最長
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = max(dp[i][j] + 1, max(dp[i+1][j], dp[i][j+1]));
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    return dp[s.size()][t.size()];
}

int main() {
    int q;
    cin >> q;
    int res[MAX_Q+1];
    for (int i = 0; i < q; i++) {
        cin >> s;
        cin >> t;
        res[i] = align_dp();
    }
    for (int i = 0; i < q; i++)
        cout << res[i] << endl;
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
using namespace std;
const int N=1e3+10;
int max(int a,int b){return a>b?a:b;}
int main(){
    int n,dp[N][N];
    string a,b;
    scanf("%d",&n);
    while(n--){
        cin>>a>>b;
        a='!'+a;
        b='@'+b;
        for(int i=0;i<a.size();i++)dp[i][0]=0;
        for(int i=0;i<b.size();i++)dp[0][i]=0;
        for(int i=1;i<a.size();i++)for(int j=1;j<b.size();j++){
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            if(a[i]==b[j])dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
        printf("%d\n",dp[a.size()-1][b.size()-1]);
    }
}

C++: 
#include<iostream>

int main(){
  int n;
  std::string x,y;
  std::cin>>n;
  int a[1000][1000];
  int b[n];

  for(int i=0;i<n;i++){
    std::cin>>x;
    std::cin>>y;
    for(int j=0;j<1000;j++){
      for(int k=0;k<1000;k++){
	a[j][k]=0;
      }
    }
    for(int j=0;j<x.size();j++){
      for(int k=0;k<y.size();k++){
	if(x[j]==y[k]){
	  a[j][k]=a[j-1][k-1]+1;
	}else{
	  if(a[j-1][k]>a[j][k-1]){
	    a[j][k]=a[j-1][k];
	  }else{
	    a[j][k]=a[j][k-1];
	  }
	}
      }
    }
    b[i]=a[x.size()-1][y.size()-1];
  }

  for(int i=0;i<n;i++){
  std::cout<<b[i]<<"\n";
  }

  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int MAX = 1000+5;
int DP[MAX][MAX];
string s1,s2;
int LCS(){
	memset(DP,0,sizeof(DP));
	int l1 = s1.size(),l2 = s2.size();
	int maxl = 0;
	s1 = ' '+s1;
	s2 = ' '+s2;
	for(int i = 1;i <= l1;i++)	DP[i][0] = 0;
	for(int j = 1;j <= l2;j++)	DP[0][j] = 0;
	for(int i = 1;i <= l1;i++){
		for(int j = 1;j <= l2;j++){
			if(s1[i] == s2[j])
				DP[i][j] = DP[i-1][j-1] + 1;
			else
				DP[i][j] = max(DP[i-1][j],DP[i][j-1]);
			maxl = max(DP[i][j],maxl);
		}
	}
	return maxl;
}
int main(int argc, char const *argv[])
{
	int T;
	cin >> T;
	while(T--){
		cin >> s1 >> s2;
		cout << LCS() << endl;
	}
	return 0;
}

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

int main(void){
    int L[1010][1010]={{0}}, Z;
    string X, Y;
    int q;
    
    cin >> q;
    for(int k=0; k<q; k++){
        cin >> X;
        cin >> Y;
    
    for(int i=0; i<X.size(); i++){
        for(int j=0; j<Y.size(); j++){
            if(i==0 || j==0){
                if(X[i]==Y[j])  L[i][j]=1;
                else            L[i][j]=0;
            }
            else if(X[i] == Y[j])    L[i][j]=1+L[i-1][j-1];
            else L[i][j]=max(L[i][j-1], L[i-1][j]);
            Z=L[i][j];
        }
    }
    
    cout << Z << endl;
    
    }
    return 0;
}

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

#define MAX_N 1000
#define MAX_M 1000

int n;
string s, t;

int dp[MAX_N + 1][MAX_M + 1];

void solve(){
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < t.size(); j++){
			if(s[i] == t[j]){
				dp[i + 1][j + 1];
					dp[i + 1][j + 1] = dp[i][j] + 1;
				} else {
					dp[i + 1][j + 1] = max(dp[i][j], dp[i + 1][j]);
				}
			}
		}
		printf("%d\n", dp[s.size()][t.size()]);
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s >> t;
		solve();
	}
}