We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a874c4b commit 982a8aaCopy full SHA for 982a8aa
minjeong/DynamicProgramming/2024-04-14-[백준]-#9251-LCS.py
@@ -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