1 / 3

11517: Exact Change

11517: Exact Change. ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11517: Exact Change 解題者: 李重儀 解題日期: 2008 年 11 月 3 日 題意: 會給你一個東西的價格,以及你所擁有的鈔票和硬幣的面額,你的程式要輸出以你的那些鈔票和硬幣所能付出能夠大於或等於那個價格的最小值,以及在那個情形下所能付出的最少硬幣 / 鈔票的數量總共是多少。.

Download Presentation

11517: Exact Change

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 11517: Exact Change • ★★★☆☆ • 題組:Contest Archive with Online Judge • 題號:11517: Exact Change • 解題者:李重儀 • 解題日期:2008年11月3日 • 題意:會給你一個東西的價格,以及你所擁有的鈔票和硬幣的面額,你的程式要輸出以你的那些鈔票和硬幣所能付出能夠大於或等於那個價格的最小值,以及在那個情形下所能付出的最少硬幣/鈔票的數量總共是多少。

  2. 題意範例:Sample Input: Output for Sample Input:1 1500 21400350010002000 • 解法:DP設f(m,x):只考慮前m個硬幣/鈔票,能付出剛好x cents這樣的數量所需使用的硬幣/鈔票數目的最小值。若無法付出剛好這麼多的數量,則為-1。f(m,x)=-1 if f(m-1,x)= -1 and (x-di<0 orf(m-1,x-di)= -1) f(m,x)=f(m-1,x) if f(m-1,x)>=0 and (x-di<0 or f(m-1,x-di)= -1)f(m,x)=f(m-1, x-di)+1 if f(m-1,x)= -1 and (x-di>=0 and f(m-1,x-di)>=0) f(m,x)=min{f(m-1,x),f(m-1, x-di)+1} otherwisef(0,0)=0 f(0,y)= -1 (y>0) (di:第i個硬幣/鈔票的幣值)

  3. 解法範例:無 • 討論:無

More Related