Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
x = int(input())
d = [0] * 30001
# 연산의 횟수를 저장.

# 보텀업 방식
for i in range(2, x + 1):
Expand Down
19 changes: 19 additions & 0 deletions 이코테/08 다이나믹 프로그래밍/바닥_공사/유진.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
n = int(input())
d = [0] * 1001
# 경우의 수를 저장

# 점화식을 어떻게 세우지?
# d[1], d[2]은 어떻게 처리할까
# d[1]은 2 x 1로 1
# d[2]은 2 x 2, 1 x 2로 2
# 이후에는
# i - 1 까지 채워져 있으면 1개의 경우가 있음
# i - 2 까지 채워져 있으면 2개의 경우가 있음
# di = di-1 + di-2 * 2

d[1] = 1
d[2] = 2
for i in range(3, n + 1):
d[i] = (d[i - 1] + d[i - 2] * 2) % 796796

print(d[n])
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
input = sys.stdin.readline

n, m = 2, 15#map(int, input().split())
money = [2, 3]
#for _ in range(n):
# money.append(int(input()))

d = [10001] * (m + 1)
# 1로 만들기 + 거스름돈 문제 같은데
# d를 10001개로 설정하는게 맞나? -> 1원이 있을 때? -> 화폐 단위별 개수를 저장하는 거라서 1001개가 맞지 않을까
# d[1] = m일 듯.
# 점화식은?
# di = min(d[i - 1], d[m//i])
d[0] = 0
for i in range(n):
for j in range(money[i], m + 1):
if d[j - money[i]] != 10001:
d[j] = min(d[j], d[j - money[i]] + 1)

if d[m] == 0:
print(-1)
else:
print(d[m])