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<vector>
#include<string>
#include<map>
using namespace std;

int dp[1145][1145];

int main(){
    int n;
    cin>>n;
    while(n--){
        string s,t;
        cin>>s>>t;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<t.size();j++){
                if(s[i]==t[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]);
            }
        }
        cout<<dp[s.size()][t.size()]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define Rep(i,n) REP(i,0,n)
typedef long long ll;

int q;
string X,Y;

int main(){
    cin>>q;
    Rep(i,q){
        cin>>X>>Y;
        X= ' '+X;
        Y= ' '+Y;
        int m,n;
        int maxl=0;
        m=X.size();
        n=Y.size();
        int c[m+3][n+3];
        Rep(j,m)Rep(k,n) c[j][k]=0;
        REP(j,1,m){
            REP(k,1,n){
                if(X[j]==Y[k]) c[j][k]=c[j-1][k-1]+1;
                else c[j][k]=max(c[j-1][k],c[j][k-1]);
                maxl=max(maxl,c[j][k]);
            }
        }
        cout<<maxl<<endl;
    }
    return 0;
}

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

int main() {
    int q; cin >> q;
    for (int i = 0; i < q; i++) {
        string s, t; cin >> s >> t;
        int n = s.size(), m = t.size();
        int dp[n+1][m+1] = {};
        for (int i= 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (s[i] == t[j]) {
                    dp[i+1][j+1] = dp[i][j] + 1;
                } else {
                    dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
                }
            }
        }
        cout << dp[n][m] << endl;
    }
}

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

int main() {
	int setN;
	cin >> setN;
	string A,B;

	for (int i=0;i<setN;i++) {
		cin >> A;
		cin >> B;
		int L[1000][1000] ={};

		for(int j=1;j<A.length()+1;j++) {
			for(int l=1;l<B.length()+1;l++) {
				if(A[j-1] == B[l-1]) {
					L[j][l] = 1+L[j-1][l-1];

				} else {
					L[j][l] = max(L[j-1][l],L[j][l-1]);
				}
				
			}
		}
		/*
		for(int j=0;j<A.length()+1;j++) {
			cout << endl;
			for(int l=0;l<B.length()+1;l++) {
				cout << L[j][l] << " ";
				
			}
		}
		*/

		cout << L[A.length()][B.length()] << endl;


	}
}

C++: #include<iostream>
#include<string>
#define lth 1000

using namespace std;

int main()
{
	int n, L[100][100], Lmax = 0, *save;
	string Xi[lth], Yi[lth];
	cin >> n;
	save = new int[n];
	for (int k = 0; k < n; k++)
	{
		Lmax = 0;
		string X, Y;
		cin >> X >> Y;
		for (int i = 0; i <= X.length(); i++)
		{
			if (i != 0)
				Xi[i] = X.substr(0, i );
		}
		for (int i = 0; i <= Y.length(); i++)
		{
			if (i != 0)
				Yi[i] = Y.substr(0, i );
		}
		for (int i = 0; i <= X.length(); i++)
			for (int j = 0; j <= Y.length(); j++)
			{
				if (i == 0 || j == 0)
					L[i][j] = 0;
				else if (Xi[i][i - 1] == Yi[j][j - 1])
				{
					L[i][j] = L[i - 1][j - 1] + 1;
				}
				else
				{
					L[i][j] = (L[i][j - 1] > L[i - 1][j]?L[i][j - 1] : L[i - 1][j]);
				}
				if (Lmax < L[i][j]) Lmax = L[i][j];
			}
		save[k] = Lmax;
	}
	for (int i = 0; i < n; i++)
		cout << save[i] << endl;
	system("pause");
}

C++: // -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_10_C: Longest Common Subsequence

#include <algorithm>
#include <cstdio>
#include <cstring>

static unsigned int lcs(const char* x, const char* y)
{
  auto m = static_cast<int>(std::strlen(x));
  auto n = static_cast<int>(std::strlen(y));
  unsigned int c1[m+1][n+1]; // extend for -1
  auto c = reinterpret_cast<int(*)[n+1]>(&c1[1][1]); // tricky?

  for (auto i = -1; i < m; ++i) c[i][-1] = 0u;
  for (auto j = 0; j < n; ++j) c[-1][j] = 0u;
  for (auto i = 0; i < m; ++i) {
    for (auto j = 0; j < n; ++j) {
      c[i][j] = (x[i] == y[j])
        ? c[i-1][j-1] + 1
        : std::max(c[i][j-1], c[i-1][j]);
    }
  }
  return c[m-1][n-1];
}

int main()
{
  unsigned int q;
  std::scanf("%u", &q);
  const unsigned int MAX_LEN = 1000;
  char x[MAX_LEN+1], y[MAX_LEN+1];
  for (auto i = 0u; i < q; ++i) {
    std::scanf("%1000s", x);
    std::scanf("%1000s", y);
    auto l = lcs(x, y);
    std::printf("%u\n", l);
  }
}

// eof

C++: #include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
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;
  REP(i, m + 1) c[i][0] = 0;
  REP(j, n + 1) c[0][j] = 0;

  REP1(i, m + 1) {
    REP1(j, n + 1) {
      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;
  REP(i, n) {
    cin >> s1 >> s2;
    cout << Lcs(s1, s2) << endl;
  }
  return 0;
}

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

#define MAX 1000

int dp[MAX+1][MAX+1];

int lcs(char x[], char y[]){
  int x_length = strlen(x);
  int y_length = strlen(y);

  for(int i = 0; i<=x_length; i++) dp[i][0] = 0;
  for(int j = 0; j<=y_length; j++) dp[0][j] = 0;

  for(int i = 1; i<=x_length; i++){
    for(int j = 1; j<=y_length; j++){
      dp[i][j] = (x[i-1] == y[j-1]) ? dp[i-1][j-1] + 1 :
                                  max(dp[i-1][j],dp[i][j-1]);
    }
  }

  return dp[x_length][y_length];
}

int main(){

  int q;
  scanf("%d", &q);

  char X[MAX + 1];
  char Y[MAX + 1];
  for(int i=0; i<q; i++){
    scanf("%s\n%s\n", X, Y);
    printf("%d\n", lcs(X, Y));
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define For(I,A,B) for(int I=(A); I < (B); ++I)
int main()
{
int t;
cin>>t;
while(t--){
int a[1000]={0},b[1000]={0},c[200][200];
int x,y,z,k=0,l,i,j;

 For(i,0,200)
 For(j,0,200)
 c[i][j]=0;


 cin>>x>>y;
 For(i,0,x+1)
 For(j,0,y+1)
 c[i][j]=0;
 For(i,1,x+1) cin>>a[i];
 For(i,1,y+1) cin>>b[i];

 For(i,1,x+1)
 For(j,1,y+1)
 {
     if(a[i]==b[j]) c[i][j]=c[i-1][j-1]+1;
     else  c[i][j]=max(c[i-1][j],c[i][j-1]);
 }
    cout<<c[x][y]<<endl;

}

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define _A_ true
using namespace std;
 
int main(){
  int n,AC=0,strA,strB;
  int dp[1010][1010];
  char *A = new char[1500];
  char *B = new char[1500];
 
  scanf("%d",&n);
  while(_A_){
    if(AC == n)break;
    scanf("%s",A);
    scanf("%s",B);
    for(int i=0;i<1010;i++)for(int j=0;j<1010;j++)dp[i][j]=0;
strA = strlen(A); 
strB = strlen(B);

    for(int i=0;i<strA;i++){
      for(int j=0;j<strB;j++){
    if(A[i] == B[j]){
      dp[i+1][j+1]=dp[i][j]+1;
    }
    else{
      if(dp[i+1][j] > dp[i][j+1]){
        dp[i+1][j+1]=dp[i+1][j];
      }
      else {
        dp[i+1][j+1] = dp[i][j+1];
      }
    }
      }
    }
    printf("%d\n",dp[strA][strB]);
    AC++;
  }
  delete [] A;
  delete [] B;
 
  return 0;
}