Go: package main

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

var (
	nstr   func() string
	stdout *bufio.Writer
)

func init() {
	nstr = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func main() {
	defer stdout.Flush()

	n := nint()
	xList := make([]string, n)
	yList := make([]string, n)

	for i:=0;i<n ;i++  {
		xList[i] = nstr()
		yList[i] = nstr()
	}

	for i := 0; i<n	; i++  {
		fmt.Println(lcs(xList[i], yList[i]))
	}

}

func lcs(x string, y string) int{
	var m = len(x)
	var n = len(y)

	c := make([][]int, m+1)
	for i:= range c{
		c[i] = make([]int, n+1)
	}
	for i:=	1;i<=m ;i++  {
		for j:=1;j<=n ;j++  {
			if x[i-1] == y[j-1]{
				c[i][j] = c[i-1][j-1] + 1
			}else{
				c[i][j] = int(math.Max(float64(c[i-1][j]), float64(c[i][j-1])))
			}


		}
	}
	return c[m][n]

}


func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func nint64() int64 {
	i, err := strconv.ParseInt(nstr(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func nint() int {
	return int(nint64())
}

func getIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = nint()
	}
	return b
}

func getStringSlice(n int) []string {
	b := make([]string, n)
	for i := 0; i < n; i++ {
		b[i] = nstr()
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func contains(s []int, e int) bool {
	for _, a := range s {
		if a == e {
			return true
		}
	}
	return false
}

func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2)
	} else {
		return strconv.FormatInt(i64, 2)
	}
}

func strReverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}

	return string(runes)
}

Python: m = int(input())
for i in range(m):
    str1 = input()
    str2 = input()
    A = [[0 for j in range(len(str1)+1)]for k in range(len(str2)+1)]
    for j in range(len(str2)):
        for k in range(len(str1)):
            if(str1[k]==str2[j]):
                A[j+1][k+1] = A[j][k]+1
            else:
                if(A[j+1][k] < A[j][k+1]):
                    A[j+1][k+1] = A[j][k+1]
                else:
                    A[j+1][k+1] = A[j+1][k]
    print(A[len(str2)][len(str1)])

Python: # coding: utf-8

def array2d(d1, d2, init = None):
    return [[init for _ in range(d2)] for _ in range(d1)]


def solve():
    x = input().strip()
    y = input().strip()

    # dp[i][j]: x[:i], y[:j] ???LCS
    # dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]+1(if x[i]==y[j]))
    dp = array2d(len(x), len(y), 0)
    dp[0][0] = int(x[0] == y[0])
    for j in range(1, len(y)):
        dp[0][j] = max(dp[0][j-1], int(x[0] == y[j]))
    for i in range(1, len(x)):
        dp[i][0] = max(dp[i-1][0], int(x[i] == y[0]))
        for j in range(1, len(y)):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            if x[i] == y[j]:
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)
    return dp[-1][-1]


def main():
    cases = int(input())
    for i in range(cases):
        print(solve())

main()

Python: query = int(input())
for _ in range(query):
    A = input().strip()
    B = input().strip()
    dp = [[0 for n in range(len(A) + 1)] for m in range(len(B) + 1)]
    for i in range(len(B) + 1):
        for inner in range(len(A) + 1):
            if i == 0:
                continue
            elif inner == 0:
                choice = dp[i - 1][inner]
            else:
                choice = max(dp[i][inner - 1], dp[i - 1][inner], dp[i - 1][inner - 1] + int(A[inner - 1] == B[i - 1]))
            dp[i][inner] = choice
#                 print(i, inner, A[inner - 1], B[i - 1])
#         print(dp)
    print(dp[len(B)][len(A)])

Python: import sys


def lcs(x, y):
    # Creating len(x + 1) * len(y + 1) table
    x = ' ' + x  # Add Space
    y = ' ' + y  # Add Space
    len_x = len(x)
    len_y = len(y)
    table = []
    for _ in range(len_y):
        table.append([0] * len_x)

    maxl = 0
    for i, x_ch in enumerate(x):
        if i == 0: continue
        for j, y_ch in enumerate(y):
            if j == 0: continue
            if x[i] == y[j]:
                table[j][i] = table[j - 1][i - 1] + 1
            else:
                table[j][i] = max(table[j - 1][i], table[j][i - 1])
            maxl = max(maxl, table[j][i])

    return maxl


if __name__ == "__main__":
    lines = [line.strip() for line in sys.stdin.readlines()[1:]]
    for sequence_pair in zip(lines[::2], lines[1::2]):
        print(lcs(*sequence_pair))

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)

Python: N = int(input())

for _ in range(N):
    x = input()
    y = input()
    m, n = len(x), len(y)
    dp = [0] * (n+1)
    
    for xi in x:
        temp = dp[:]
        for j in range(n):
            if xi == y[j]:
                dp[j+1] = temp[j] + 1
            elif dp[j+1] < dp[j]:
                dp[j+1] = dp[j]
                
    print(dp[-1])

Python: q = int(input())
ans = []
for i in range(q):
    x = input()
    y = input()
    n = len(x)
    m = len(y)
    dp1 = [0]*(m+1)
    for i in range(n):
        s = x[i]
        dp2 = dp1[:]
        for j in range(m):
            if s == y[j]:
                dp1[j+1] = dp2[j]+1
            elif dp1[j+1] < dp1[j]:
                dp1[j+1] = dp1[j]
    ans.append(dp1[-1])
print(*ans, sep="\n")

Python: from __future__ import print_function
from sys import stdin
def lcs(x, y):
    m = len(x)
    n = len(y)
    c = [[0]*(n + 1) for a in range(m + 2)]
    for i in xrange(1, m + 1):
        for j in xrange(1, n + 1):
            if x[i-1] == y[j-1]:
                c[i][j] = c[i - 1][j - 1] + 1
            else:
                c[i][j] = max(c[i - 1][j], c[i][j - 1])
    return max(max(c))
 
n = int(raw_input().rstrip())
strs = stdin.readlines()
ret = []
for i in xrange(n):
    s1 = strs[i*2].rstrip()
    s2 = strs[i*2+1].rstrip()
    ret.append(lcs(s1, s2))
print(*ret, sep="\n")