Skip to content

Commit 982a8aa

Browse files
committed
[BOJ] #9251. LCS / 골드5 / 46분 (힌트사용)
1 parent a874c4b commit 982a8aa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
str_A = input().strip()
5+
str_B = input().strip()
6+
LCS = [[0 for j in range(len(str_B)+1)] for i in range(len(str_A)+1)] #LCS 배열 초기화
7+
8+
for i in range(1, len(str_A)+1):
9+
for j in range(1, len(str_B)+1):
10+
# 한 글자씩 비교
11+
if str_A[i-1] == str_B[j-1]: # 같으면 이전 값에 +1
12+
LCS[i][j] = LCS[i-1][j-1] + 1
13+
else: # 다르다면 A 부분수열과 B 부분수열 중 더 큰 값을 선택
14+
LCS[i][j] = max(LCS[i-1][j], LCS[i][j-1])
15+
16+
print(max(max(LCS))) # LCS 배열에서 가장 큰 값을 리턴

0 commit comments

Comments
 (0)