Skip to content

Commit 01dc628

Browse files
committed
[BOJ]#20542.받아쓰기/골드5/힌트
https://www.acmicpc.net/problem/20542
1 parent 43c75c8 commit 01dc628

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Hongjoo/백준/받아쓰기.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
백준 #20542. 받아쓰기/DP /골드5
3+
https://www.acmicpc.net/problem/20542
4+
5+
(1) 문자가 같음 -> 대각선 = 현위치
6+
(2) 다른 문자
7+
min (왼쪽[add] , 대각선[edit] , 위) +1
8+
"""
9+
import sys
10+
N , M = map(int, sys.stdin.readline().split())
11+
predict =list(*map(str,sys.stdin.readline().split()))
12+
gt = list(*map(str,sys.stdin.readline().split()))
13+
print(predict , gt)
14+
# predict -> gt
15+
dp = [[0 for _ in range(len(gt)+1)] for k in range(len(predict)+1)]
16+
dp[0] = list(range(len(gt)+1))
17+
print(dp)
18+
for i in range(1,len(predict)+1):
19+
for j in range(len(gt)+1) :
20+
# 초기화
21+
if j==0 :
22+
dp[i][j] = dp[i-1][j]+ 1 # 위 +1
23+
continue
24+
25+
# dp 채우기
26+
if predict[i] == gt[j]:
27+
dp[i][j] = dp[i-1][j-1]
28+
print(f"samep { dp}")
29+
else :
30+
dp[i][j] = 1 + min(dp[i-1][j-1] , dp[i][j-1] , dp[i-1][j])
31+
32+
print(dp)

0 commit comments

Comments
 (0)