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(){
	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<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=0;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;

int main(){
    int num;
    cin >> num;
    for(int ii=0; ii<num; ii++){
        // 文字列の受け取り
        string s, t;
        cin >> s >> t;
        int n = s.size(), m = t.size();

        // DPテーブルの準備
        int dp[n+1][m+1] = {};
        //dp[0][0] = 0;

        // DPテーブルを更新
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
                else dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }

        // 答えの出力
        cout << dp[n][m] << endl;
    }
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int m[1000][10000];
int main(){
  int n;
  cin>>n;
  char A[1001];
  char B[1001];
  for(int i=0;i<n;i++){
    cin>>A;
    cin>>B;
    int x;
    int y;
    for(x=0;A[x]!='\0';x++){
      for(y=0;B[y]!='\0';y++){
	if(A[x]==B[y]){
	  m[x+1][y+1]=m[x][y]+1;
	}
	else {
	  if(m[x][y+1]>m[x+1][y]){
	    m[x+1][y+1]=m[x][y+1];
	  }
	  else m[x+1][y+1]=m[x+1][y];
	}
      }
    }
    cout<<m[x][y]<<endl;

  }

  
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#define MAX 1000
using namespace std;

int LCS() {
    int i, j, maxl;
    string X, Y;
    int C[MAX+1][MAX+1];

    cin >> X >> Y;
    size_t X_len = X.length();
    size_t Y_len = Y.length();

    for (i=0; i<=X_len; i++) {
        for (j=0; j<=Y_len; j++) {
            if (i==0 || j==0) C[i][j]=0;
            else {
                if (X[i]==Y[j]) {
                    C[i][j]=C[i-1][j-1]+1;
                    maxl = max(C[i][j], maxl);
                } else C[i][j]=max(C[i-1][j], C[i][j]);
            }
        }
    }

    return maxl;
}

int main() {
    int n, i;
    
    cin >> n;
    for (i=0; i<n; i++) {
        printf("%d\n", LCS());
    }

    return 0;
}

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

int LCS(string X, string Y) {
  /*
  if (X.length() == 0 || Y.length() == 0) {
    return 0;
  }
  else if (X[X.length()-1] == Y[Y.length()-1]) {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return LCS(miniX, miniY) + 1;
  }
  else {
    string miniX = X.substr(0, X.length()-1),  miniY = Y.substr(0, Y.length()-1);
    return max(LCS(miniX, Y), LCS(X, miniY));
  }
  */
 int m = X.length(), n = Y.length();
 int c[m+1][n+1];
 for (int i = 0; i <= m; i++) {c[i][0] = 0;}
 for (int i = 0; i <= n; i++) {c[0][i] = 0;}
 int maxL = 0;
 X = ' '+ X; Y = ' ' + Y;
 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][j-1], c[i-1][j]);
  maxL = max(maxL, c[i][j]);   
  }
 }
 return maxL;
}
int main(void) {
  int q; cin >> q;
  string X[q], Y[q];
  for (int i = 0; i < q; i++)  {
    cin >> X[i] >> Y[i];
  }

  int ans[q];
  for (int i = 0; i < q; i++) {
    ans[i] = LCS(X[i], Y[i]);
  }

  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX_SEQ 1000

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

  for(int i=0;i<n;i++) {
    int subseq_len = 0;
    char seq1[MAX_SEQ+1];
    char seq2[MAX_SEQ+1];
    vector<char> seq_sub;
    cin >> seq1;
    cin >> seq2;

    for(int seq1_it=0;seq1[seq1_it]!='\0';seq1_it++) {
      vector<char>::iterator it = find(seq_sub.begin(), seq_sub.end(), seq1[seq1_it]);
        if (it == seq_sub.end()) {
          seq_sub.push_back(seq1[seq1_it]);
        }
    }
    for(int seq2_it=0;seq2[seq2_it]!='\0';seq2_it++) {
      vector<char>::iterator it = find(seq_sub.begin(), seq_sub.end(), seq2[seq2_it]);
        if (it != seq_sub.end()) {
          seq_sub.erase(it);
          subseq_len++;
        }
    }
    cout << subseq_len << endl;
  }
}

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;

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

	for( int i = 0; i < q; i++ ) {
		string X, Y;
		cin >> X >> Y;
		int m = X.size();
		int n = Y.size();
		vector<vector<int>> c( m + 1, vector<int>( n + 1 ) );
		for( int j = 1; j < m + 1; j++ ) {
			for( int k = 1; k < n + 1; k++ ) {
				if( X[j - 1] == Y[k - 1] ) {
					c[j][k] = c[j - 1][k - 1] + 1;
				}
				else {
					c[j][k] = max( c[j][k - 1], c[j - 1][k] );
				}
			}
		}
		cout << c[m][n] << endl;
	}
}