Go: package main

import (
	. "fmt"
    "math"
)

// func init() { Println("----------------------------------------") }

func main() {
    const L_MAX = 1003

	var q int
	Scanf("%d", &q)
	X := make([]string, 0, 150)
	Y := make([]string, 0, 150)
	for i := 0; i < 2 * q; i++ {
	    var tmp string
	    Scanf("%s", &tmp)

	    if i % 2 == 0 {
	        X = append(X, tmp)
	    } else {
	        Y = append(Y, tmp)
	    }
	}

    for i := 0; i < q; i++ {
        dp := make([][]int, L_MAX)
        for k, _ := range dp {
            dp[k] = make([]int, L_MAX)
        }

        x, y := X[i], Y[i]

        // init
        isXFound := false
        for c := 0; c < len(x); c++ {
            if isXFound || y[0] == x[c] {
                dp[0][c] = 1
                isXFound = true
            }
        }
        isYFound := false
        for r := 0; r < len(y); r++ {
            if isYFound || x[0] == y[r] {
                dp[r][0] = 1
                isYFound = true
            }
        }

        for r := 1; r < len(y); r++ {
            for c := 1; c < len(x); c++ {
                // dp[r][c]
                if x[c] == y[r] {
                    dp[r][c] = int(math.Max(float64(dp[r - 1][c - 1] + 1), float64(dp[r][c])))
                }

                dp[r][c] = int(math.Max(float64(dp[r][c]), math.Max(float64(dp[r - 1][c]), float64(dp[r][c - 1]))))
            }
        }
        Println(dp[len(y) - 1][len(x) - 1])

        // LCSも求めておく
        // ans := ""
        // r, c := len(y) - 1, len(x) - 1
        // for r >= 0 && c >= 0 {
        //     if y[r] == x[c] {
        //         ans = string(x[c]) + ans
        //         r--
        //         c--
        //     } else {
        //         if dp[r - 1][c] > dp[r][c - 1] {
        //             r--
        //         } else {
        //             c--
        //         }
        //     }
        // }
        // Println(ans)
    }
}

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

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;


int lcs(string x, string y) {
    int c[1001][1001];
    int n = x.length();
    int m = y.length();
    for(int i = 0; i < n; i++) {
        c[i][0] = 0;
    }
    for(int j = 0; j < m; j++) {
        c[0][j] = 0;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(x[i-1] == y[j-1]) {
                c[i][j] = c[i-1][j-1] + 1;
            } else {
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
        }
    }
    return c[n][m];
}

int main() {
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        string s1, s2;
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }
}