Go: package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		scanner.Scan()
		s1 := scanner.Text()
		scanner.Scan()
		s2 := scanner.Text()
		s1, s2 = " " + s1 , " " + s2
		c := make([][]int, len(s1))
		for i := range c {
			c[i] = make([]int, len(s2))
		}

		LCS := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					c[i][j] = c[i-1][j-1] + 1
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1])
				}
				LCS = max(LCS, c[i][j])
			}
		}
		fmt.Println(LCS)
	}
}

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

int temp[MAX][MAX];
int main(){
	int q;
	string x, y;
	
	cin>>q;
	
	for(int i = 1; i <= q; i++){
		cin>>x>>y;
		int sx = x.size() ,sy = y.size();
		for(int j = 0; j <= sx; j++)for(int k = 0; k <= sy; k++)temp[j][k] = 0;
		for(int j = 0; j < sx; j++){
			for(int k = 0; k < sy; k++){
				if(x[j] == y[k]){
					temp[j+1][k+1] = max(temp[j][k]+1,temp[j+1][k+1]);
				} else temp[j+1][k+1] = max(temp[j+1][k],temp[j][k+1]);
			}
		}
		cout<<temp[sx][sy]<<endl;
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define if_range(x, w, h) if (w <= x && x <= h)
#define BitCheck(a,b)   (a >> b) & 1
#define BitSet(a,b)       a |= (1 << b)
#define BitunSet(a,b)    a &= ~(1 << b)

int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }

int main() {
	int n, m, a, dp[102][102] = { 0 };
	char s[1001], t[1001];
	scanf("%d", &a);
	for (int k = 0; a > k; k++) {
		scanf("%d %d %s %s", &n, &m, s, t);
		for (int i = 1; n >= i; i++) {
			for (int j = 1; m >= j; j++) {
				if (s[i - 1] == t[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;
				else dp[i][j] = __max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
		printf("%d\n", dp[n][m]);
	}
	return 0;
}

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

void LCS(string X, string Y){
    X = ' ' + X; //＋演算子でX[0]に空白を挿入
    Y = ' ' + Y;
    int C[X.length()][Y.length()];
    
    for (int i = 0; i < X.length(); i++){
        C[i][0] = 0;
    }
    for (int i = 0; i < Y.length(); i++){
        C[0][i] = 0;
    }
    
    for (int i = 1; i < X.length(); i++){
        for (int j = 1; j < Y.length(); 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]);
        }
    }
    cout << C[X.length()-1][Y.length()-1] << endl;
    
}

int main(){
    int n;
    string X, Y;
    cin >> n;
    
    for (int i = 0; i < n; i++ ){
        cin >> X;
        cin >> Y;
        LCS(X, Y);
    }
    
    return 0;
}

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 = 0; 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 <iostream>
#include <algorithm>
using namespace std;

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

string str1, str2;
int dp[1001][1001];
int k;

int solve(int i, int j)
{
  if(dp[i][j] >= 0)
    return dp[i][j];
  if(i >= str1.size() || j >= str2.size()){
    if(i < str1.size()){
      dp[i][j - 1] = 0;
      return solve(i + 1, k);
    }else{
      return 0;
    }
  }
  if(str1[i] == str2[j]){
    k = j + 1;
    int n, m = 0;
    for(int l = i + 1; l < str1.size(); l++){
      n = solve(l, j + 1);
      m = (n > m) ? n : m;
    }
    dp[i][j] = m + 1;
    return dp[i][j];
  }else{
    return solve(i, j + 1);
  }
}
  
int main()
{
  int q, n, m, ans = 0;
  cin >> q;
  cin.ignore();
  REP(i, q){
    getline(cin, str1);
    getline(cin, str2);
    if(str1.size() < str2.size())
      swap(str1, str2);
    fill(&dp[0][0], &dp[1001][0], -1);
    REP(j, str1.size()){
      n = solve(j, 0);
      ans = (n > ans) ? n : ans;
    }
    cout << ans << endl;
    ans = 0;
  }
}

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

int lcs(string X,string Y){
	int c[1001][1001];
	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<iostream>
#include<vector>
#include<string>
using namespace std;
const int NIL = -1;
void SearchMaxSubString(string & a,string & b,
						vector<vector<int> > & maxlen,
						int s,
						int t)
{
	int lengthAB = 0;
	if (a[s] == b[t]) {
		lengthAB++;
		if ((s+1) < (int)a.size() && (t+1) < (int)b.size()) {
			if (maxlen[s+1][t+1] == NIL) {
				SearchMaxSubString(a,b,maxlen,s+1,t+1);
			}
			lengthAB += maxlen[s+1][t+1];
		}
		maxlen[s][t] = lengthAB;
	}
	else {
		int lengthA = 0;
		int lengthB = 0;
		if ((s+1) < (int)a.size()) {
			if (maxlen[s+1][t] == NIL) {
				SearchMaxSubString(a,b,maxlen,s+1,t);
			}
			lengthA = maxlen[s+1][t];
		}
		if ((t+1) < (int)b.size()) {
			if (maxlen[s][t+1] == NIL) {
				SearchMaxSubString(a,b,maxlen,s,t+1);
			}
			lengthB = maxlen[s][t+1];
		}
		maxlen[s][t] = std::max(lengthA,lengthB);
	}
}

int main(){
	int n;
	cin >> n;
	for(; n > 0; --n) {
		string a,b;
		cin >> a >> b;
		vector<vector<int> > maxlen;
		maxlen.resize(a.size());
		for(unsigned int i=0;i<a.size();++i) {
			maxlen[i].resize(b.size());
			for(unsigned j=0;j<maxlen[i].size();++j){
				maxlen[i][j] = NIL;
			}
		}
		SearchMaxSubString(a,b,maxlen,0,0);
		cout << maxlen[0][0] << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
int main(){
  int q;
  std::cin>>q;
  int i,j,k;
  std::string x,y;
  int a[1001][1001];
  int knum[q];
  for(i=0; i<1001; i++){
    for(j=0; j<1001; j++){
      a[i][j]=0;
    }
  }
  for(k=0; k<q; k++){
    std::cin>>x;
    std::cin>>y;
    for(i=1; i<x.size()+1; i++){
      for(j=1; j<y.size()+1; j++){
	if(x[i-1]==y[j-1]){
	  a[i][j]=a[i-1][j-1]+1;
	}else{
	  if(a[i-1][j]>a[i][j-1]){
	    a[i][j]=a[i-1][j];
	  }else{
	    a[i][j]=a[i][j-1];
	  }
	}
      }	
    }
    knum[k]=a[x.size()][y.size()];
  }
  for(k=0; k<q; k++){
    std::cout<<knum[k]<<"\n";
  }
  return 0;
}