Skip to content

Commit

Permalink
#45 9251.py
Browse files Browse the repository at this point in the history
  • Loading branch information
HanMulBit committed Sep 3, 2024
1 parent 0f0873b commit c3fae14
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions aiden/class4-2/9251.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def lcs(s1, s2):

dp = [[0] * (len(s2) + 1) for _ in range(len(s1) + 1)]

for i in range(1, len(s1) + 1):
for j in range(1, len(s2) + 1):
if s1[i-1] == s2[j-1]:
dp[i][j] = dp[i-1][j-1] + 1

else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])

return dp[len(s1)][len(s2)]

s1 = input().strip()
s2 = input().strip()

print(lcs(s1,s2))

0 comments on commit c3fae14

Please sign in to comment.