Go: package main

import (
	"fmt"
)

func main() {
	var q int
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var x, y string
		fmt.Scan(&x)
		fmt.Scan(&y)

		xs := []rune(x)
		ys := []rune(y)

		xn := len(xs)
		yn := len(ys)
		dp := make([][]int, xn+1)
		for j := 0; j <= xn; j++ {
			dp[j] = make([]int, yn+1)
		}

		for j := 1; j <= xn; j++ {
			for k := 1; k <= yn; k++ {
				dp[j][k] = max(dp[j-1][k], dp[j][k-1])
				if xs[j-1] == ys[k-1] {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1] + 1)
				} else {
					dp[j][k] = max(dp[j][k], dp[j-1][k-1])
				}
			}
		}
		fmt.Println(dp[xn][yn])
	}
}

func max(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <string.h>

using namespace std;
const int N_MAX = 1000;
char x[N_MAX+10], y[N_MAX+10];
int dp[N_MAX][N_MAX];

void solve() {
  int i, j;
  scanf("%s", x);
  scanf("%s", y);
  int N = strlen(x);
  int M = strlen(y);
  //printf("N = %d M = %d", N, M);
  for (i = 0; i < N+1; i++) {
    dp[i][0] = 0;
  }
  for (j = 0; j < M+1; j++) {
    dp[0][j] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      if (x[i] == y[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]);
      }
    }
  }
  printf("%d\n", dp[N][M]);
} 

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    solve();
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#define DATA_SIZE 1001

using namespace std;

int lcs(int dp[][DATA_SIZE], string x, string y){
    int xl = x.size();
    int yl = y.size();
    
    for(int i = 1; i <= xl; i++){
        for(int j = 1; j <= yl; j++){
            if(x[i-1] == y[j-1]){ 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, dp[DATA_SIZE][DATA_SIZE] = {};
    string X, Y;

    cin >> q;
    for(int i = 0; i < q; i++){
        cin >> X >> Y;
        cout << lcs(dp, 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>
#include <algorithm>
using namespace std;
int dp[1002][1002];

int main(){
	int n;cin >> n;
	string x, y;
	while(n--){
		fill((int*)dp, (int*)(dp+1002), 0);
		cin >> x >> y;
		for(int i = 1;i <= x.size();i++){
			for(int j = 1;j <= y.size();j++){
				if(x[i-1] == y[j-1])dp[i][j] = dp[i-1][j-1] + 1;
				else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
		cout << dp[x.size()][y.size()] << endl;
	}
	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>
#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<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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	int max = 0;
	for (int i = x_begin; X[i] != '\0'; i++) {
		for (int j = y_begin; Y[j] != '\0'; j++) {
			if (X[i] == Y[j]) {
				int v_lcs = lcs(i + 1, j + 1);
				if (v_lcs + 1 > max) {
					max = v_lcs + 1;
				}
			}
		}
	}
	return table_lcs[x_begin][y_begin] = max;

}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;
	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		Y = stringY.c_str();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

using namespace std;
const int N_MAX = 1000;
char x[N_MAX+10], y[N_MAX+10];
int dp[N_MAX][N_MAX];

void solve() {
  int i, j;
  scanf("%s", x);
  scanf("%s", y);
  int N = strlen(x);
  int M = strlen(y);
  //printf("N = %d M = %d", N, M);
  for (i = 0; i < N+1; i++) {
    dp[i][0] = 0;
  }
  for (j = 0; j < M+1; j++) {
    dp[0][j] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      if (x[i] == y[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]);
      }
    }
  }
  printf("%d\n", dp[N][M]);
} 

int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    solve();
  }
  return 0;
}

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

int dp[2000][2000];

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  while(n--){
    string sa, sb; cin >> sa >> sb;
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= sa.size(); i++){
      for(int j = 1; j <= sb.size(); j++){
        if(sa[i] == sb[j]){
          dp[i][j] = dp[i-1][j-1] + 1;
        }else{
          dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
      }
    }
    cout << dp[sa.size()][sb.size()] << endl;
  }
  return 0;
}