Skip to content

Commit

Permalink
Merge pull request #71 from AlgoLeadMe/15-avocado-13
Browse files Browse the repository at this point in the history
15-avocado-13
  • Loading branch information
avocado-13 authored Feb 21, 2024
2 parents ce60728 + ba40930 commit 858e75a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions avocado-13/다이나믹 프로그래밍/1로 만들기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n = int(input())
d = [0] * (n + 1) ## d에 계산된 값을 저장해둔다. n + 1이라고 한 이유는, 1번째 수는 사실 d[1]이 아니고 d[2]이기 때문에, 계산하기 편하게 d[1]을 1번째 인 것 처럼 만들어준다.

for i in range(2, n + 1):

d[i] = d[i - 1] + 1
if i % 3 == 0:
d[i] = min(d[i], d[i // 3] + 1)
if i % 2 == 0:
d[i] = min(d[i], d[i // 2] + 1)
print(d[n])

0 comments on commit 858e75a

Please sign in to comment.