๋ฌธ์
https://www.acmicpc.net/problem/5582
๋ด ๋ฌธ์ ํ์ด
import sys
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
cnt = [[0 for _ in range(len(b) + 1)] for _ in range(len(a) + 1)]
for i in range(len(a)):
for j in range(len(b)):
if a[i] == b[j]:
cnt[i+1][j+1] = cnt[i][j] + 1
print(max(map(max, cnt)))
๐ DP, ๋ฌธ์์ด ๋ฌธ์
2์ฐจ์ ๋ฐฐ์ด์ ๋ง๋ค๊ณ , ๋๊ฐ์ ์ผ๋ก ์ฐ์๋๋ ๋ฌธ์์ด์ ์นด์ดํธํด์ ๋์ ํด์ฃผ๋ฉด ๋๋ค.
๐ก ํผ๋๋ฐฑ
์๊ฐ์ด๊ณผ, ๋ฉ๋ชจ๋ฆฌ ์ด๊ณผ๋ฅผ ์ฃผ์ํด์ ํ์ด์ผ ํ๋ค.
๊ทผ๋ฐ ๋ ์๋ฌด๋ฆฌ ํ์ด๋ ํ๊ณ๊ฐ ์์ด์ ๊ฒฐ๊ตญ pypy๋ก ์ ์ถํ๋ค.ใ
๋ค์์ ๋ค์ ํ ๋ฒ ํ์ด๋ด์ผ๊ฒ ๋ค,,
'4๏ธโฃ Python > Problem Solving' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python Algorithm] AC BOJ #5430 (0) | 2022.05.24 |
---|---|
[Python Algorithm] ์ ํ๋ฒํธ ๋ชฉ๋ก BOJ #5052 (0) | 2022.05.24 |
[Python Algorithm] N๊ณผ M (4) BOJ #15652 (0) | 2022.02.15 |
[Python Algorithm] N๊ณผ M (3) BOJ #15651 (0) | 2022.02.15 |
[Python Algorithm] N๊ณผ M (2) BOJ #15650 (0) | 2022.02.15 |
๋๊ธ