Any kind of advice and help is more than welcomed

This is a discussion on Any kind of advice and help is more than welcomed within the C Programming forums, part of the General Programming Boards category; I AM A DUMMY, PLEASE MAKE IT SIMPLE- Thanx You have an (arbitrary) set of coins C which have integer ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Any kind of advice and help is more than welcomed

    I AM A DUMMY, PLEASE MAKE IT SIMPLE- Thanx

    You have an (arbitrary) set of coins C which have integer values. The only restrictions on C are:
    a) All the coins have positive integer values
    b) C must contain the coin of value 1

    The problem to be solved is to specify the minimum number of coins which can be used to make up a given amount of change.

    For example suppose that C = {1, 3, 7, 10} and you are asked to make up 25. You can do this in various ways:

    10 + 10 + 3 + 1 + 1
    10 + 10 + 1 + 1 + 1 + 1 + 1
    10 + 7 + 7 + 1
    7 + 7 + 7 + 3 + 1
    …….and so on…….

    As it turns out the solution 10+7+7+1 is optimal in this case.

    I need to build two different solutions to the giving change problem:

    •simple greedy algorithm (always take the largest coin available)
    •stochastic search (take coins at random)

    ANY IDEA HOW TO START.

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I AM A DUMMY, PLEASE MAKE IT SIMPLE
    Well the simplest way would be using for loops and if statements.

    Make an array for your coin set.

    You could do something like this

    Code:
    #define PENNY  0
    #define NICKEL 1
    #define DIME   2
    
    int Change[3] = {1, 5, 10};
    Then you would use a loop and keep checking values.

    you could say "if change[dime] + change[dime] is > than the value, try change[dime] + change[nickel]"

    Thats the easiest way I can think of.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    2
    Ok... I will try this one. Thanks alot. I let you know.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21