File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments