page435.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 47 行
HTML
47 行
<HTML><HEAD><TITLE>Example-Counting Change</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html6185" HREF="page436.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6183" HREF="page434.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6177" HREF="page434.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6187" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H2><A NAME="SECTION0014110000000000000000">Example-Counting Change</A></H2><A NAME="secalgschange"> </A><P>Consider the problem a cashier solvesevery time he counts out some amount of currency.The cashier has at his disposal a collection ofnotes and coins of various denominationsand is required to count out a specified sumusing the smallest possible number of pieces.<P>The problem can be expressed mathematically as follows:Let there be <I>n</I> pieces of money (notes or coins), <IMG WIDTH=138 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67613" SRC="img1698.gif" >,and let <IMG WIDTH=13 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline63883" SRC="img1191.gif" > be the denomination of <IMG WIDTH=14 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline57875" SRC="img85.gif" >.For example, if <IMG WIDTH=14 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline57875" SRC="img85.gif" > is a dime, then <IMG WIDTH=51 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline67621" SRC="img1699.gif" >.To count out a given sum of money <I>A</I>we find the smallest subset of <I>P</I>, say <IMG WIDTH=43 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline67627" SRC="img1700.gif" >,such that <IMG WIDTH=95 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline67629" SRC="img1701.gif" >.<P>One way to represent the subset <I>S</I> is to use <I>n</I> variables <IMG WIDTH=143 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67635" SRC="img1702.gif" >, such that<P> <IMG WIDTH=309 HEIGHT=48 ALIGN=BOTTOM ALT="displaymath67605" SRC="img1703.gif" ><P>Given <IMG WIDTH=104 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67637" SRC="img1704.gif" > our <em>objective</em>is to minimize<P> <IMG WIDTH=269 HEIGHT=44 ALIGN=BOTTOM ALT="displaymath67606" SRC="img1705.gif" ><P>subject to the constraint<P> <IMG WIDTH=294 HEIGHT=44 ALIGN=BOTTOM ALT="displaymath67607" SRC="img1706.gif" ><P><BR> <HR><UL> <LI> <A NAME="tex2html6188" HREF="page436.html#SECTION0014111000000000000000">Brute-Force Algorithm</A><LI> <A NAME="tex2html6189" HREF="page437.html#SECTION0014112000000000000000">Greedy Algorithm</A></UL><HR><A NAME="tex2html6185" HREF="page436.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6183" HREF="page434.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6177" HREF="page434.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html6187" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?