# 9251 LCS def LCS(SA,SB,SALEN,SBLEN): global LCS_list for i in range(1,SALEN+1): for j in range(1,SBLEN+1): if SA[i-1] == SB[j-1]: LCS_list[i][j] = LCS_list[i-1][j-1]+1 else: LCS_list[i][j] = max(LCS_list[i-1][j],LCS_list[i][j-1]) A = list(input()) B = list(input()) lenA = len(A) lenB = len(B) LCS_list = [[0]*(lenB+1) for _ in range(lenA+1)] LCS(A,B,lenA,lenB) print(LCS_list[lenA][lenB])
이전에 풀었던 LCS의 이전버전이다.
푸는 방식은 동일하고 여기서는 길이만 구해주는거라 길이만 구해줬다.
'알고리즘 > 백준' 카테고리의 다른 글
[BOJ/백준] 1309 동물원 (0) | 2021.01.31 |
---|---|
[BOJ/백준] 11403 경로찾기 (0) | 2021.01.30 |
[BOJ/백준] 14499 주사위 굴리기 (0) | 2021.01.29 |
[BOJ/백준] 9633 N-queen (0) | 2021.01.28 |
[BOJ/백준] 2174 로봇 시뮬레이션 (0) | 2021.01.26 |