# How to approach greedy in problem set 1? [closed]

I do not have a clear idea of how greedy can be solved.

I do not understand this currency or what the question asks.

• Why do you tag your name in each of your questions? That feature is provided for fast searching of questions on basis of various topics, what's the logic of tagging your name into it? Jul 26 '14 at 2:31
• Because it's a `tag` ;) When you `tag` someone on FB you enter his/her name... Jul 26 '14 at 19:36
• This is not a specific question. Try elaborating on what you are looking for. Jul 29 '14 at 22:38

You are given a value of dollars and cents. You must calculate the least number of coins that can be used to make that value. The coins available are worth 25 cents (quarter), 10 cents (dime), 5 cents (nickel), and 1 cent (penny).

Let's say you are asked for 1.32

1.32 is 132 cents. So how many coins would you need? To get the least number of coins, you should start with the coin with the highest value (the quarter or 25 cent coin).

So, 132 cents / 25 cents = 5 so you have 5 quarters (worth 25*5 = 125 cents).

That means you still need coins for 132 - 125 cents which is 7 cents.

Next, try your next coin value, which is 10 cents.

7 cents / 10 cents = 0 (so that means you can't use any dimes)

Next, try nickels

7 cents / 5 cents = 1 (so one nickel), leaving 7-5 = 2 cents (2 pennies)

So, total coins is 5 + 0 + 1 + 2 = 8

I hope that is understandable.

CS50 provides a variety of resources to help their students including walkthroughs for the each of the problem sets. The walkthroughs help get you started and show how you should be thinking about solving the problems presented. I've listed the link to the CS50 walkthrough on greedy.c