Skip to content

Commit 26680a5

Browse files
committed
[BOJ] #20542. 받아쓰기 / 골드3 / 50분 / 성공
1 parent c7d95ad commit 26680a5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
# 입력
5+
n, m = map(int, input().split())
6+
write_str = " " + input().strip()
7+
answer_str = " " + input().strip()
8+
9+
# DP
10+
dp = [[0] * (n + 1) for _ in range(m + 1)]
11+
12+
# 공집합 채우기
13+
for i in range(1, m + 1):
14+
dp[i][0] = i
15+
for j in range(1, n + 1):
16+
dp[0][j] = j
17+
18+
# 최소 편집으로 DP 채우기
19+
for i in range(1, m + 1):
20+
for j in range(1, n + 1):
21+
if write_str[j] == answer_str[i] or \
22+
(write_str[j] == 'i' and answer_str[i] == 'j') or \
23+
(write_str[j] == 'i' and answer_str[i] == 'l') or \
24+
(write_str[j] == 'v' and answer_str[i] == 'w'):
25+
dp[i][j] = dp[i - 1][j - 1]
26+
else:
27+
dp[i][j] = min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]) + 1
28+
29+
# 정답 출력
30+
print(dp[m][n])

0 commit comments

Comments
 (0)