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)])
	}
}

Python: from itertools import chain
from sys import stdin
def lcs(x, y):
    m = len(x)
    n = len(y)
    c = [[0] * 1001 for i in range(1002)]
    # x = " " + x
    # y = " " + y
    for i in range(1, m + 1):
        for j in range(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(chain.from_iterable(c))


n = int(input().rstrip())
strs = stdin.readlines()
ret = []
for i in range(n):
    s1 = strs[i*2].rstrip()
    s2 = strs[i*2+1].rstrip()
    ret.append(lcs(s1, s2))
print(*ret, sep="\n")

Python: def LCS(x,y):
    n,m=len(x),len(y)
    DP=[0 for _ in range(m+1)]
    for i in range(n):
        tmp=DP[:]
        num=x[i]
        for j in range(m):
            if num==y[j]:DP[j+1]=tmp[j]+1
            elif DP[j+1]<DP[j]:DP[j+1]=DP[j]
    return DP[-1]


n=int(input())
for _ in range(n):
    print(LCS(input(),input()))

Python: e=input
a=[]
for _ in[0]*int(e()):
 X,z=e(),[]
 for y in e():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 a+=[z]
print('\n'.join(map(str,map(len,a))))

Python: #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
abcbdab
bdcaba
abc
abc
abc
bc

output:
4
3
2

"""
import sys

sys.setrecursionlimit(int(1e5))


def lcs(w1, w2):
    m, n = len(w1), len(w2)
    dp = tuple([[0] * (n + 1) for _ in range(m + 1)])
    max_l = 0
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if w1[i - 1] == w2[j - 1]:
                dp[i][j] = dp[i - 1][j - 1] + 1
            else:
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
            max_l = max(max_l, dp[i][j])

    return max_l


def lcs_recursive(w1, w2, m, n):
    if m == 0 or n == 0:
        return 0
    elif w1[m - 1] == w2[n - 1]:
        return 1 + lcs_recursive(w1, w2, m - 1, n - 1)
    else:
        return max(
            lcs_recursive(w1, w2, m, n - 1), lcs_recursive(w1, w2, m - 1, n))


def solve():
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = _input[1:]
    # assert len(word_list) == 2 * pair_num

    for pair in zip(word_list[::2], word_list[1::2]):
        cw1, cw2 = map(lambda x: x.strip(), pair)
        # print(lcs(cw1, cw2))
        print(lcs_recursive(cw1, cw2, len(cw1), len(cw2)))

    return None


if __name__ == '__main__':
    solve()

Python: # coding=utf-8

def lcs(X, Y):
    global c
    m = len(X)
    n = len(Y)
    max_c = 0
    for i in range(0, m):
        for j in range(0, n):
            if X[i] == Y[j]:
                if (i == 0) or (j == 0):
                    c[i][j] = 1
                else:
                    c[i][j] = c[i-1][j-1] + 1
            else:
                c[i][j] = max(c[i-1][j], c[i][j-1])
            if c[i][j] > max_c:
                max_c = c[i][j]
    return max_c

q = int(input())

for _ in range(q):
    X = list(input())
    Y = list(input())
    c = [[0 for _ in range(len(Y))] for _ in range(len(X))]
    max_c = lcs(X, Y)
    print(max_c)

Python: def answer(X, Y):
    m, n = len(X), len(Y)
    C = [[0] * (n + 1) for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(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][j -1], C[i -1][j])
    return C[m][n]


if __name__ == '__main__':
    q = int(input())
    for _ in range(q):
        X = input()
        Y = input()
        print(answer(X, Y))

Python: # -*- coding: utf-8 -*-


if __name__ == '__main__':

    
    def lcs(X, Y):
        m = len(X)
        n = len(Y)
        c = [[-1 for i in range(n+1)] for j in range(m+1)]
        X = " " + X
        Y = " " + Y
        for i in range(m+1):
            c[i][0] = 0
        for j in range(1, n+1):
            c[0][j] = 0
        for i  in range(1, m+1):
            for j in range(1, 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])
        return c[m][n]

    def lcs2(X, Y):
        n = len(Y)
        dp = [0]*(n+1)
    
        for c in X:
            tmp = dp[:]
            for j in range(n):
                if c == Y[j]:
                    dp[j+1] = tmp[j] + 1
                elif dp[j+1] < dp[j]:
                    dp[j+1] = dp[j]
    
        return dp[-1]

    q = int(input())
    for _ in range(q):
        X = input()
        Y = input()
        print(lcs2(X,Y))

Python: def lcs(s1,s2):
    l1=len(s1)
    work=[0]*(l1+1)

    #enumerateを使って文字列へのアクセスを極力避ける
    for x in s2:
        work_old=work[:]
        for j,y in enumerate(s1):
            if x==y :
                work[j+1]=work_old[j]+1
            elif work[j]>work_old[j+1]:
                work[j+1]=work[j]
                
    print(work[-1])


import sys
input=sys.stdin.readline


q=int(input())
for _ in range(q):
    lcs(input()[:-1],input()[:-1])

Python: q = int(input())
ans = []

for i in range(q):
    s1 = input()
    n1 = len(s1)
    s2 = input()
    n2 = len(s2)

    f = [[0 for j in range(n2)] for i in range(n1)]
    if s1[0] == s2[0]:
        f[0][0] = 1
    else:
        f[0][0] = 0

    for j in range(1, n2):
        if f[0][j-1] == 0:
            if s1[0] == s2[j]: delta = 1
            else: delta = 0
            f[0][j] = f[0][j-1]+delta
        else:
            f[0][j] = f[0][j-1]

    for i in range(1, n1):
        if f[i-1][0] == 0:
            if s1[i] == s2[0]: delta = 1
            else: delta = 0
            f[i][0] = f[i-1][0]+delta
        else:
            f[i][0] = f[i-1][0]

    for i in range(1, n1):
        for j in range(1, n2):
            if s1[i] == s2[j]:
                f[i][j] = f[i-1][j-1]+1
            else:
                f[i][j] = max(f[i-1][j], f[i][j-1])

    ans.append(f[n1-1][n2-1])
    #print(f)

for a in ans:
    print(a)

Python: q = int(input())
for _ in range(q):
    x = input()
    y = input()
    m = len(x)
    n = len(y)
    c = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
    for i in range(1, m + 1):
        tmp = x[i - 1]
        for j in range(1, n + 1):
            if tmp == y[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
            elif c[i - 1][j] >= c[i][j - 1]:
                c[i][j] = c[i - 1][j]
            else:
                c[i][j] = c[i][j - 1]
    print(c[m][n])

Python: #coding:UTF-8
def LCS(X,Y):
    count=0
    xlist=list(X)
    ylist=list(Y)
    anslist=[]
    ynum=0
    xnum=0
    yflag=False
    for i in range(len(ylist)):
        for j in range(i,len(xlist)):
            anslist.append([j,i])
    for i in range(len(anslist)):
        if xlist[anslist[i][0]]==ylist[anslist[i][1]] and ynum==anslist[i][1] and anslist[i][0]>xnum:
            count+=1
            yflag=True
            ynum+=1
            xnum=anslist[i][0]
        if anslist[i][0]==len(xlist)-1:
            if yflag==True:
                yflag=False
            else:
                ynum+=1
    print(count)
if __name__=="__main__": 
    n=int(input())
    for i in range(n):
        X=input()
        Y=input()
        LCS(X,Y)