Skip to content

Commit efd1d2e

Browse files
authored
Merge pull request #73 from zaqquum/main
Hongjoo/ 10월 3주차 / 2문제
2 parents 3679d59 + 999ec93 commit efd1d2e

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

Hongjoo/기타/못생긴수.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#정올 : https://jungol.co.kr/problem/1318
2+
3+
import sys
4+
5+
n= int(sys.stdin.readline())
6+
while n != 0 :
7+
# dp 세팅하기
8+
# ugly = [ 0 for _ in range(n)]
9+
ugly= list()
10+
ugly.append(1)
11+
# 기존 array
12+
nums = [2,3,5]
13+
14+
for i in range(n) :
15+
tmp = [ ugly[i] * j for j in nums]
16+
ugly += tmp #이전 ugly에 추가
17+
ugly= set(ugly) # 중복 제거
18+
ugly = list(ugly)
19+
ugly.sort() # 정렬
20+
21+
print(ugly[n-1])
22+
n= int(sys.stdin.readline())
23+

Hongjoo/백준/계단 오르기.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
iteration 2
1212
dp[i] : Max(dp[i-1] + step[i]
1313
14+
## 실패 -> 재도전
1415
'''
1516
# input
1617
import sys

Hongjoo/백준/최소편집.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
'''
3+
Y축 (before) -> X 축 after)
4+
5+
A[i]=B[j] 같으면 : 유지 ->대각선: dp[i,j] = dp[i-1,j-1]
6+
A[i]!=B[j]의 경우 : 교체 -> 대각선 +1
7+
8+
if len(Y) > len(X) : # 빼기 => top down +1
9+
if len(Y) < len(X) : # 추가 => +1 left-right(->)
10+
dp[i][j]= min(왼,위,대각선) +1
11+
12+
'''
13+
import sys
14+
before =[0]+ list(sys.stdin.readline())[:-1]
15+
after = [0] + list(sys.stdin.readline())[:-1]
16+
dp = [[0 for _ in range(len(after))] for k in range(len(before))]
17+
18+
# 2. 최소 편집 거리
19+
20+
for i in range(len(before)):
21+
for j in range(len(after)) :
22+
# 2-1최소 편집 거리 map 초기화
23+
if i== 0 and j>0:
24+
dp[i][j] = dp[i][j-1]+1 # i=0
25+
elif j == 0 and i > 0 :
26+
dp[i][j] = dp[i-1][j]+1
27+
# 2-2 최소 편집 거리 점화식
28+
else :
29+
b = before[i]
30+
a = after[j]
31+
32+
if a == b :#유지
33+
dp[i][j] = dp[i-1][j-1]
34+
else : # 추가 , 빼기 , 교체 중 가장 편집 거리가 적은 경우+1
35+
dp[i][j] = min(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]) +1 #
36+
# print(f"-{b},{a} : {dp[i][j]} ")
37+
38+
39+
print(f"{b} -> {a} : dp[{i}{j}] : {dp[i][j]}")
40+
print("")
41+
# print(dp)
42+
43+
# print("-------------")
44+
print(dp[-1][-1])

0 commit comments

Comments
 (0)