Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	Q := sc.nextInt()
	for q := 0; q < Q; q++ {
		X, Y := sc.nextStr(), sc.nextStr()
		xLen, yLen := len(X), len(Y)
		dp := make([][]int, xLen+1)
		for i := 0; i <= xLen; i++ {
			dp[i] = make([]int, yLen+1)
		}
		for x := 0; x <= xLen; x++ {
			for y := 0; y <= yLen; y++ {
				if x == 0 || y == 0 {
					dp[x][y] = 0
				} else if X[x-1] == Y[y-1] {
					dp[x][y] = dp[x-1][y-1] + 1
				} else {
					dp[x][y] = max(dp[x-1][y], dp[x][y-1])
				}
			}
		}
		fmt.Fprintln(wtr, dp[xLen][yLen])
	}

	wtr.Flush()
}

C++: #include <cstdio>
#include <cmath>
#define MAX 1002
using namespace std;

int Lcc(const char *X, const char *Y) {
    int lcc = 0;
    int dp[MAX][MAX];
    for (int i=0; i<MAX; i++)
        for (int j=0; j<MAX; j++) dp[i][j] = 0;

    int x=1, y=1;
    for (int i=0;;i++) {
        if (X[i] == ',') {x = i;break;}
        for (int j=0;;j++) {
            if (Y[j] == ',') {
                y = j;
                break;
            }
            if (Y[j] == ',') {
                y = j;
                break;
            } else {
                if (X[i] == Y[j]) {
                    dp[i+1][j+1] = fmax(dp[i][j] + 1, dp[i+1][j]);
                } else {
                    dp[i+1][j+1] = fmax(dp[i+1][j], dp[i][j+1]);
                }
            }
        }
    }
    return dp[x-1][y-1];
}

int
main()
{
    int q;
    scanf("%d", &q);
    for (int i=0; i<(q); i++) {
        char X[MAX], Y[MAX];
        for (int i=0; i<MAX; i++) {
            X[i] = ','; Y[i] = ',';
        }
        scanf(" %s", X);scanf(" %s", Y);
        int LCC = Lcc(X, Y);
        printf("%d\n", LCC);
    }
    return 0;
}

C++: #include <stdio.h>

int score[1010][1010];

int max2 (int a, int b){
  if (a >= b) return a;
  else return b;
}

int len_of_str(const char s[]){
  int num = 0;

  while(s[num]) num++;

  return num;
}


int main() {
  char a[1010];
  char b[1010];
  int datanum;
  scanf("%d",&datanum);
  for(int c = 0; c < datanum; c++){

  scanf("%999s",a);
  scanf("%999s",b);
  int num1 = len_of_str(a);
  int num2 = len_of_str(b);


  for(int i = num1; i > 0; i--) a[i] = a[i - 1];
  a[0] = ' ';
  for(int j = num2; j > 0; j--) b[j] = b[j - 1];
  b[0] = ' ';

  for(int i = 0; i <= num1; i++) score[i][0] = 0;
  for(int j = 0; j <= num2; j++) score[0][j] = 0;

  int maximum = 0;

  for(int i = 1; i<= num1; i++){
    for (int j = 1; j <= num2; j++){
      if (a[i] == b[j])score[i][j] = score[i-1][j-1] + 1;
      else max2(score[i][j-1],score[i-1][j]);
      maximum = max2(maximum,score[i][j]);
    }
  }

  printf("%d\n",maximum);
}
  return 0;
}

C++: #include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll q;
  cin >> q;
  for (ll testcase = 0; testcase < q; ++testcase) {
    string a, b;
    cin >> a >> b;
    vector<vector<ll>> dp(a.size() + 1, vector<ll>(b.size() + 1, 0));
    for (ll i = 0; i < a.size(); ++i) {
      for (ll j = 0; j < b.size(); ++j) {
        if (a.at(i) == b.at(j)) {
          dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1);
        }
        dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j));
        dp.at(i).at(j + 1) = max(dp.at(i).at(j + 1), dp.at(i).at(j));
        dp.at(a.size()).at(j + 1) = max(dp.at(a.size()).at(j), dp.at(a.size()).at(j + 1));
      }
      dp.at(i + 1).at(b.size()) = max(dp.at(i + 1).at(b.size()), dp.at(i).at(b.size()));
    }
    cout << dp.at(a.size()).at(b.size()) << "\n";
    // for (ll i = 0; i <= a.size(); ++i) {
    //   for (ll j = 0; j <= b.size(); ++j) {
    //     cout << dp.at(i).at(j) << " ";
    //   }
    //   cout << "\n";
    // }
  }
}

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

int lcs(string X,string Y)
{
    int x=X.size(),y=Y.size();
    int dp[y+1][x+1];

    for(int i=0;i<x+1;i++)dp[0][i]=0;
    for(int i=1;i<y+1;i++)dp[i][0]=0;
    int maxl=0;
    
    for (int j = 1; j <= y; j++){
        for (int k = 1; k <= x ; k++){
            if (Y[j-1]==X[k-1]) dp[j][k]=dp[j-1][k-1]+1;
            else dp[j][k]=max(dp[j][k-1],dp[j-1][k]);
            maxl=max(maxl,dp[j][k]);
        }
    }
    return maxl;
}

int main()
{
    int q;
    cin>>q;
    string X,Y;
    for (int i = 0; i < q; i++) {
        cin>>X>>Y;
        cout<<lcs(X,Y)<<endl;
    }
}
/*
3
abcbdab
bdcaba
abc
abc
abc
bc
*/

C++: #include "stdio.h"
#include<iostream>
#include<string>
#include<algorithm>

#define MAX 1000

using namespace std;

int lcs(string input1, string input2){
  int m = input1.length();
  int n = input2.length(); 

  input1 = " " + input1;
  input2 = " " + input2; 

  //Singleton?
  int c[MAX+1][MAX+1];
    
  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(input1[i] == input2[j]){
        c[i][j] = c[i-1][j-1] + 1;
      }else{
        c[i][j] = max(c[i-1][j], c[i][j-1]);
      }
    
    }     
  }
  return c[m][n];
}

int main(void){
  
  int N;
  scanf("%d", &N);

  string  input1, input2;

  for(int i=0;i<N;i++){
    cin >> input1;
    cin >> input2;
    printf("%d\n", lcs(input1, input2));
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rp(i,j) for(long long i=0;i<j;i++)
#define rep(i,j,k) for(long long i=j;i<k;i++)
#define mod 1000000007
#define NIL -1
typedef long long ll;
int lcs(string x,string y){
    int dp[1001][1001];
    int maxl=0;
    int X=x.size(),Y=y.size();
    x=" "+x;y=" "+y;
    rp(j,X+1)dp[j][0]=0;
    rp(j,Y+1)dp[0][j]=0;
    rep(j,1,X+1){
        rep(k,1,Y+1){
            if(x[j]==y[k])dp[j][k]=dp[j-1][k-1]+1;
            else dp[j][k]=max(dp[j-1][k],dp[j][k-1]);
        }
    }
    return dp[X][Y];
}
int main(){
    int q;cin>>q;
    rp(i,q){
        string s1,s2;
        cin>>s1>>s2;
        cout<<lcs(s1,s2)<<endl;
    }
}