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] = dp[i-1][j-1]+1
				} else if S[i-1] != T[j-1] && dp[i-1][j] > dp[i][j-1] {
					dp[i][j] = dp[i-1][j]
				} else {
					dp[i][j] = dp[i][j-1]
				}
				// 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 <stdio.h>
#include <string.h>

int cache[1001][1001];
const int INF = 1 << 20;

int max(int x, int y) { if (x < y) return y; else return x; }

int lcs(char *x, char *y, int xl, int yl) {
	if (cache[xl][yl] != INF) {
		return cache[xl][yl];
	}
	if (xl == 0 || yl == 0) return 0;
	if (x[xl-1] == y[yl-1]) {
		return cache[xl][yl] = lcs(x, y, xl - 1, yl - 1) + 1;
	} else {
		return cache[xl][yl] = max(lcs(x, y, xl - 1, yl), lcs(x, y, xl, yl - 1));
	}
}

int main(void) {
	int q;
	scanf("%d\n", &q);
	for (int i = 0; i < q; i ++) {
		char X[1000];
		char Y[1000];
		for (int i = 0; i <= 1000; i ++) {
			for (int j = 0; j <= 1000; j ++) {
				cache[i][j] = INF;
			}
		}
		gets(X);
		gets(Y);
		printf("%d\n", lcs(X, Y, strlen(X), strlen(Y)));
	}
	return 0;
}

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

int main(){
  int n;
  std::cin>>n;
  int B[1500]={0};
  for(int k=0;k<n;k++){
    std::string str1;
    std::string str2;
    std::cin>>str1;
    std::cin>>str2;
    int A[1000][1000]={0};
    /*初期化？*/
    for(int i=0;i<str1.size();i++){
      if(str1[i]==str2[0]){
	A[i][0]=1;
      }
      if(i>0){
	A[i][0]=std::max(A[i][0],A[i-1][0]);
      }
    }
    for(int j=0;j<str2.size();j++){
      if(str1[0]==str2[j]){
	A[0][j]=1;
      }
      if(j>0){
	A[0][j]=std::max(A[0][j],A[0][j-1]);
      }
    }
    for(int i=1;i<str1.size();i++){
      for(int j=1;j<str2.size();j++){
	if(str1[i]==str2[j]){
	  A[i][j]=A[i-1][j-1]+1;
	}else{
	  A[i][j]=std::max(A[i-1][j],A[i][j-1]);
	}
      }
    }
    B[k]=A[str1.size()-1][str2.size()-1];
  }
  for(int i=0;i<n;i++){
    std::cout<<B[i]<<"\n";
  }
  return 0;
}

C++: // 17D8104010B 宮本拓輝 10_c c++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
  int score[1001][1001];
  int n;
  cin>>n;
  int result[n];
  for(int s=0;s<n;s++){
    string x,y;
    cin>>x;
    cin>>y;

    for(int i=0;i<x.size();i++){
      for(int j=0;j<y.size();j++){
        if(x[i]==y[j]){
          score[i+1][j+1]=score[i][j]+1;
        }
        else{
          score[i+1][j+1]=max(score[i+1][j],score[i][j+1]);
        }
      }
    }
    //cout<<score[x.size()][y.size()]<<"\n";
    result[s]=score[x.size()][y.size()];

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

  return 0;
}

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

#define MAX 150
#define MAXL 1000

int C[MAXL][MAXL];

int lec(string X,string Y)
{
    int XL = X.length();
    int YL = Y.length();
    for(int i=0;i<XL;i++)
        C[i][0] = 0;
    for(int i=0;i<YL;i++)
        C[0][i] = 0;
    for(int i=0;i<XL;i++)
    {
        for(int j=0;j<YL;j++)
        {
            if(X[i]==Y[j])
            {
                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];
            }
        }
    }
    return C[XL-1][YL-1];
}

int main()
{
    int q;
    string x,y;
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>x>>y;
        cout<<lec(x,y)<<endl;
    }
    return 0;
}

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

const int MAX_X = 1000, MAX_Y = 1000;

int main() {
  int n;
  int dp[MAX_X+1][MAX_Y+1];
  string X, Y;
  cin >> n;
  for (int k=0; k<n; k++) {
    cin >> X >> Y;
    for (int i=0; i<=X.length(); i++) {
      for (int j=0; j<=Y.length(); j++) {
        dp[i][j] = 0;
      }
    }

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

    cout << dp[X.length()][Y.length()] << endl;
  }
  return 0;
}

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

string X, Y;
int lc[1005][1005];

int getLCS(int m, int n) {
	if (m < 0 || n < 0)
		return 0;
	if (lc[m][n] != -1)
		return lc[m][n];
	if (X[m] == Y[n]) 
		return lc[m][n] = getLCS(m - 1, n - 1) + 1;
	else
		return lc[m][n] = max(getLCS(m, n - 1), getLCS(m - 1, n));
}

int main(void) {
	int i, j;
	int nu;
	cin >> nu;
	while (nu--) {
		for (i = 0; i < 1005; i++) 
			for (j = 0; j < 1005; j++) 
				lc[i][j] = -1;
		cin >> X >> Y;
		int m = X.length() - 1, n = Y.length() - 1;
		int lcs = getLCS(m, n);
		cout << lcs << endl;
	}
}

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

typedef long long llong;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int q;
	cin >> q;
	while (q--) {
		string a, b;
		cin >> a >> b;
		int n = a.length(), m = b.length();
		vector<int> prev(m + 1, 0);
		for (int i = 1; i <= n; ++i) {
			vector<int> current(m + 1);
			current[0] = 0;
			for (int j = 1; j <= m; ++j) {
				if (a[i - 1] == b[j - 1]) {
					current[j] = 1 + prev[j - 1];
				} else {
					current[j] = max(current[j - 1], prev[j]);
				}
			}
			prev = current;
		}
		cout << prev[m] << '\n';
	}

	return 0;
}