๋ฌธ์ ์ค๋ช
LCS → ๋ชจ๋์ ๋ถ๋ถ ์์ด์ด ๋๋ ์์ด ์ค ๊ฐ์ฅ ๊ธด ๊ฒ์ ์ฐพ๋ ๋ฌธ์ ..!
- ์์ ์ค์ํ๊ฐ ? → ๊ทธ๋ฐ๋ฏ..!
ํ์ด์ฌ ์ฝ๋
A = list(input())
B = list(input())
len_A = len(A)
len_B = len(B)
# dp = []
# dp = [[0] * (len_B + 1)] * (len_A + 1)
dp = [[0] * (len_B + 1) for _ in range(len_A + 1)]
for i in range(1, len_A + 1):
for j in range(1, len_B + 1):
if A[i-1] == B[j - 1]:
dp[i][j] = dp[i-1][j-1] + 1
else:
dp[i][j] = max(dp[i-1][j], dp[i][j-1])
print(dp[len_A][len_B]) # dp table ๋งจ ๋ง์ง๋ง ๊ฐ ์ถ๋ ฅ
'์๊ณ ๋ฆฌ์ฆ ๐ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 9095. 1, 2, 3 ๋ํ๊ธฐ | ํ์ด์ฌ (0) | 2024.07.19 |
---|---|
[๋ฐฑ์ค] 11048. ์ด๋ํ๊ธฐ | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 1149. RGB๊ฑฐ๋ฆฌ | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 1461. ๋์๊ด | ํ์ด์ฌ (0) | 2024.07.19 |
[๋ฐฑ์ค] 2579. ๊ณ๋จ ์ค๋ฅด๊ธฐ | ํ์ด์ฌ (0) | 2024.07.18 |