Data Structures and Algorithms with Object-Oriented Design Patterns in Python
next up previous index

Example-Counting Change

 

Consider the problem a cashier solves every time he counts out some amount of currency. The cashier has at his 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_inline67613, and let tex2html_wrap_inline63883 be the denomination of tex2html_wrap_inline57875. For example, if tex2html_wrap_inline57875 is a dime, then tex2html_wrap_inline67621. To count out a given sum of money A we find the smallest subset of P, say tex2html_wrap_inline67627, such that tex2html_wrap_inline67629.

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

displaymath67605

Given tex2html_wrap_inline67637 our objective is to minimize

displaymath67606

subject to the constraint

displaymath67607




next up previous index

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