Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Example-Counting Change

 

Consider the problem a cashier solves every time she counts out some amount of currency. The cashier has at her disposal a collection of notes and coins of various denominations and is required to count out a specified sum using the smallest possible number of pieces.

The problem can be expressed mathematically as follows: Let there be n pieces of money (notes or coins), tex2html_wrap_inline68403, and let tex2html_wrap_inline64564 be the denomination of tex2html_wrap_inline58415. E.g., if tex2html_wrap_inline58415 is a dime, then tex2html_wrap_inline68411. To count out a given sum of money A we find the smallest subset of P, say tex2html_wrap_inline68417, such that tex2html_wrap_inline68419.

One way to represent the subset S is to use n variables tex2html_wrap_inline68425, such that

displaymath68395

Given tex2html_wrap_inline68427 our objective is to minimize

displaymath68396

subject to the constraint

displaymath68397




next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.