Go: package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	for i := 0; i < num; i++ {
		sc.Scan()
		in1 := sc.Text()
		sc.Scan()
		in2 := sc.Text()
		countMax(in1, in2)
	}
}

func countMax(in1 string, in2 string) {
	counta := make([][]int, len(in2)+1)
	for i := 0; i < len(in2)+1; i++ {
		for j := 0; j < len(in1)+1; j++ {
			counta[i] = append(counta[i], 0)
		}
	}

	// fmt.Println(counta)
	for a1, v1 := range in1 {
		i1 := a1 + 1
		for a2, v2 := range in2 {
			i2 := a2 + 1
			// fmt.Printf("1:%v 2:%v\n", i1, i2)
			if v1 == v2 {
				counta[i2][i1] = counta[i2-1][i1-1] + 1
				continue
			}
			val := counta[i2-1][i1]
			if val < counta[i2][i1-1] {
				val = counta[i2][i1-1]
			}

			counta[i2][i1] = val
		}
	}
	fmt.Println(counta[len(in2)][len(in1)])
}

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;
	}


}

C++: #include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); i++)
#define ll long long
using namespace std;

int main() {
  int n; cin>>n;
  rep(q, n) {
    string X,Y; cin>>X>>Y;
    int x=X.size();
    int y=Y.size();
    vector<vector<int>> dp(x+1,vector<int>(y+1, 0));
    rep(i, x) {
      rep(j, y) {
        dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
        if (X[i]==Y[j]) dp[i+1][j+1]=max(dp[i+1][j+1], dp[i][j]+1);
      }
    }
    cout<<dp[x][y]<<endl;
  }
}

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

constexpr int MAX_XY = 1000;

int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;

void fill_dp(){
    for(int i = 1; i <= lx; ++i){
        for(int j = 1; j <= ly; ++j){
            if(sx[i] == sy[j]) dp[i][j] = dp[i - 1][j - 1] + 1;
            else dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
}

void solve(){
    fill_dp();
    std::cout << dp[lx][ly] << std::endl;
    return;
}

int main(){
    std::cin >> q;
    
    for(int i = 0; i < q; ++i){
        std::cin >> sx >> sy;
        lx = sx.size(), ly = sy.size();
        solve();
    }
    return 0;
}

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

using namespace std;

int q;
char X[1000], Y[1000];
int dp[1001][1001];

int main(void) {

    scanf("%d", &q);

    for (int i = 0; i < q; ++i) {
        scanf("%s %s", X, Y);
        int xlen = strlen(X), ylen = strlen(Y);
        for (int x = 0; x < xlen; ++x) {
            for (int y = 0; y < ylen; ++y) {
                if (X[x] == Y[y]) {
                    dp[x + 1][y + 1] = dp[x][y] + 1;
                }
                else {
                    if (dp[x + 1][y] > dp[x][y + 1]) {
                        dp[x + 1][y + 1] = dp[x + 1][y];
                    }
                    else {
                        dp[x + 1][y + 1] = dp[x][y + 1];
                    }
                }
            }
        }
        printf("%d\n", dp[xlen][ylen]);
//        memset(dp, 0, sizeof(int)*1001*1001);
    }

    return 0;
}

C++: 
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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;
}