๋ฌธ์
https://www.acmicpc.net/problem/9251
ํ์ด
# ๋ฐฑ์ค 9251๋ฒ ๋ฌธ์ - LCS
str1 = ' ' + input()
str2 = ' ' + input()
dp = [[0]*len(str1) for _ in range(len(str2))]
for i in range(1, len(str2)):
for j in range(1, len(str1)):
if str2[i] == str1[j]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
print(dp[-1][-1])
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 2512๋ฒ_์์ฐ (0) | 2023.04.22 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1107๋ฒ_๋ฆฌ๋ชจ์ปจ (1) | 2023.04.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1011๋ฒ_Fly me to the Alpha Centauri (0) | 2023.04.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 2447๋ฒ_๋ณ ์ฐ๊ธฐ - 10 (0) | 2023.04.21 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold4] 7662๋ฒ_์ด์ค ์ฐ์ ์์ ํ (0) | 2023.04.20 |