Skip to content

Commit 64465d8

Browse files
committed
2 parents 754023f + efd1d2e commit 64465d8

File tree

6 files changed

+143
-0
lines changed

6 files changed

+143
-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])
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
# 좋은 수열인지 검사하는 함수 (유망성 검사 함수)
6+
def is_good(sequence):
7+
length = len(sequence)
8+
for i in range(1, length // 2 + 1):
9+
# 인접한 두 부분 수열이 동일한 경우 False
10+
if sequence[-i:] == sequence[-2 * i:-i]:
11+
return False
12+
return True
13+
14+
15+
def backtracking(sequence, n):
16+
# 종료 조건: 수열의 길이가 n이면 출력하고 프로그램 종료
17+
if len(sequence) == n:
18+
print(sequence)
19+
exit()
20+
21+
for num in "123":
22+
new_sequence = sequence + num # 새로운 수를 붙여봄
23+
if is_good(new_sequence): # 좋은 수열인지 확인
24+
backtracking(new_sequence, n) # 재귀 호출로 다음 수 탐색
25+
26+
n = int(input()) # 수열의 길이
27+
backtracking("", n)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
A = input().strip()
5+
B = input().strip()
6+
7+
# 2차원 배열 초기화: (len(A)+1) x (len(B)+1) 크기
8+
dp = [[0] * (len(B) + 1) for _ in range(len(A) + 1)]
9+
10+
# 초기값 설정: 빈 문자열에서 변환 비용
11+
for i in range(len(A)+1):
12+
dp[i][0] = i
13+
for i in range(len(B)+1):
14+
dp[0][i] = i
15+
16+
# DP 배열 채우기
17+
for i in range(1, len(A)+1):
18+
for j in range(1, len(B)+1):
19+
if A[i-1] == B[j-1]: # 문자가 같다면 교체 비용 X(왼쪽 대각선 값)
20+
dp[i][j] = dp[i-1][j-1]
21+
else: # 다르다면 왼쪽, 위쪽, 왼쪽 대각선 위 중 최소값에 중 +1
22+
dp[i][j] = min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]) + 1
23+
24+
# 최소 편집 횟수 출력
25+
print(dp[-1][-1])
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
n = int(input())
2+
if n == 1:
3+
print("*")
4+
exit()
5+
6+
# 첫번째 줄
7+
print(" " * (n-1) + "*")
8+
9+
# 가운데 줄
10+
for i in range(1, n-1):
11+
print(" " * (n - i - 1) + "*" + " " * (2 * i - 1) + "*")
12+
13+
# 마지막 줄
14+
print("*"*(2*n-1))
15+
16+
'''
17+
n = int(input())
18+
for i in range(1, n+1):
19+
if(i==1 or i==n):
20+
print(" " * (n-i) + "*" * (2*i-1))
21+
else:
22+
print(" " * (n-i) + "*" + " " * (2*(i-1)-1) + "*")
23+
'''

0 commit comments

Comments
 (0)