Epic - Coin Change
Something cost $10.25 and the customer pays with a $20 bill, the program will print out the most efficient "change-breakdown" which is 1 five, 4 ones, and 3quarters. Find the minimum number of coins required to make change for a given sum (given unlimited cumber of N different denominations coin)
动态规划:dp数组存储的元素表示需要达到该下标值时所需要的最小硬币数,转移方程为 dp[i] = min(dp[i],dp[i-x]+1)
def coin_change(coin,sum)
dp = Array.new(sum+1,sum) #the sum is integer
dp[0] = 0
(1..sum).each {|i| coin.each {|x| dp[i] = [dp[i],dp[i-x]+1].min if x <= i}}
dp[-1]
end
Epic - Coin Change的更多相关文章
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2069 Coin Change
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...
- JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)
JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划) B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...
- C - Coin Change (III)(多重背包 二进制优化)
C - Coin Change (III) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Coin Change (IV) (dfs)
Coin Change (IV) Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu [Subm ...
- Coin Change (II)(完全背包)
Coin Change (II) Time Limit: 1000MS Mem ...
- [LeetCode] Coin Change 2 硬币找零之二
You are given coins of different denominations and a total amount of money. Write a function to comp ...
随机推荐
- 在struts-config.xml中配置validator-plugin导致404 Servlet action is not available
就是在struts-config.xml中添加了这么一段 <plug-in className="org.apache.struts.validator.ValidatorPlugIn ...
- Angular service
<!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...
- C# 将字符串转化成流,将流转换成字符串
using System; using System.IO; using System.Text; namespace CSharpConvertString2Stream { class Progr ...
- HDU 4652 Dice(期望)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652 题意:一个m个面的筛子.两种询问:(1)平均抛多少次后使得最后n次的面完全一样:(2)平均抛多少 ...
- win7 64位系统 Oracle32bit + PL/SQL访问Orale服务,Oracle 11g的安装,中文乱码问题的解决
前几天装了个Oracle32bit客户端 + PL/SQL连接不上oracle,我安装完打开PL/SQL登录界面跟正常的界面不一样,没有那个连接为Normal.SYSDBA的选项,下面有解释,至于我为 ...
- easyui datagrid列中使用tooltip
要实现这样一个效果:数据加载到DATAGRID中,鼠标移至某一列时,会弹出tooltip提示框. 最初的实现方法: { field: 'Reply', title: '备注', width: 220, ...
- BZOJ3306: 树
3306: 树 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 311 Solved: 86[Submit][Status] Description ...
- (转载)UITableView使用详解
在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...
- (转载)ios关闭虚拟键盘的几种方法
在iOS应用开发中,有三类视图对象会打开虚拟键盘,进行输入操作,但如何关闭虚拟键盘,却没有提供自动化的方法.这个需要我们自己去实现.这三类视图对象分别是UITextField,UITextView和U ...
- UIView的user Interaction Enabled属性
A Boolean value that determines whether user events are ignored and removed from the event queue. 译: ...