Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code is updated #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
45 changes: 32 additions & 13 deletions Greedy algorithm prob. in pyhton/Money change/moneychng.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
n = int(input())
count = 0
while n>0:
if n >= 10:
count+=1
n = n-10
elif n>=5:
count+=1
n = n-5
elif n>=1:
count+=1
n=n-1
print(count)
import sys

def get_change(m):
#write your code here
coins = [1, 3, 4]
cash = [0] * (m +1)
if m <= 1:
return m
cash[0] = 0
cash[1] = 1
#cash[3] = 1
#cash[4] = 1
coinreplacments = []
for i in range(2, m + 1):
for y in coins:
if i == y:
#cash[i] = 1
coinreplacments.append(1)
elif i > y:

coinreplacments.append(cash[i - y] + cash[y])
else:
pass

cash[i] = min(coinreplacments)
coinreplacments.clear()

return cash[m]

if __name__ == '__main__':
m = int(sys.stdin.read())
print(get_change(m))