Source: 最长公共子序列 - 蓝桥云课 (lanqiao.cn)
题解
python
N,M=map(eval,input().split())
a=input().split()
b=input().split()
DP=[ [0 for i in range(M+1)] for j in range(N+1)]
for i in range(1,N+1):
for j in range(1,M+1):
if a[i-1]==b[j-1]:
DP[i][j]=DP[i-1][j-1]+1
else:
DP[i][j]=max(DP[i-1][j],DP[i][j-1])
print(DP[N][M])