Go: // AOJ ALDS1_10_C: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

package main

import (
	"fmt"
)

func main() {
	var dataNum int
	var s1, s2 string

	fmt.Scanf("%d", &dataNum)

	for i := 0; i < dataNum; i++ {
		fmt.Scanf("%s", &s1)
		fmt.Scanf("%s", &s2)

		lcs := make([][]int, len(s1)+1)
		for j := 0; j < len(s1)+1; j++ {
			lcs[j] = make([]int, len(s2)+1)
		}

		for m, vs1 := range s1 {
			for n, vs2 := range s2 {
				if vs1 == vs2 {
					lcs[m+1][n+1] = lcs[m][n] + 1
				} else if lcs[m+1][n] > lcs[m][n+1] {
					lcs[m+1][n+1] = lcs[m+1][n]
				} else {
					lcs[m+1][n+1] = lcs[m][n+1]
				}
			}
		}

		// Answer
		fmt.Println(lcs[len(s1)][len(s2)])
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
    using namespace std;
int lcs(string x,string y){
    int c[1010][1010];
    int m = x.size();
    int n = y.size();
    int maxl=0;
    x = ' '+x;
    y = ' '+y;
    for (int i=1; 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(){
    int q;
    string x;
    string y;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        cin>>x>>y;
        cout<<lcs(x, y)<<endl;
    }
    return 0;
}

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

using namespace std;

int dp[1001][1001];

int lcs(string x, string y) {
    int lx = x.size(), ly = y.size();
    for (int i = 1; i <= ly; ++i) {
        for (int j = 1; j <= lx; ++j) {
            dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1] + (x[j - 1] == y[i - 1]));
        }
    }
    return dp[ly][lx];
}

int main() {
    int n;
    string x, y;
    cin >> n;
    while (n--) {
        cin >> x >> y;
        cout << lcs(x, y) << endl;
    }

    return 0;
}

C++: 	#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e18;
	const ll MOD = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	
	signed main(){
		IOS;
		ll q;
		cin >> q;
		REP(i, q){
			string s, t;
			cin >> s >> t;
			int n = s.size();
			int m = t.size();
			vec<vec<ll>> dp(n + 1,vec<ll>(m + 1,0));
			REP(i, n)REP(j, m){
				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]);
			}
			dump(dp[n][m]);
		}
	}

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

static const int max_n = 1000;
string s1, s2;
int q, c[max_n + 1][max_n + 1];

int lcs(string X, string Y){
	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 if(c[i - 1][j] >= c[i][j - 1]){
				c[i][j] = c[i - 1][j];
			}
			else{
				c[i][j] = c[i][j - 1];
			}
			maxl = max(maxl, c[i][j]);
		}
	}
	return maxl;
}

int main(void){
	cin >> q;
	for( int i = 1; i <= q; i++ ){
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}