leetcode322—Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.
Example 1:
Input: coins =[1, 2, 5], amount =11Output:3Explanation: 11 = 5 + 5 + 1
Example 2:
Input: coins =[2], amount =3Output: –1
想法:采用动态规划,状态转移表达式为result[amount]=result[amount-coins]+1;
class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
int len = coins.size();
vector<);
result[] = ;
int max = INT_MAX;
; i <= amount ;i++ ){
result[i] = max;
; j < coins.size() ; j++){
<result[i]){
result[i] = result[i-coins[j]] + ;
}
}
}
if(result[amount] == max){
;
}else{
return result[amount];
}
}
};
leetcode322—Coin Change的更多相关文章
- leetcode322 Coin Change
""" You are given coins of different denominations and a total amount of money amount ...
- Leetcode322. Coin Change零钱兑换
给定不同面额的硬币 coins 和一个总金额 amount.编写一个函数来计算可以凑成总金额所需的最少的硬币个数.如果没有任何一种硬币组合能组成总金额,返回 -1. 示例 1: 输入: coins = ...
- [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 ...
随机推荐
- JavaScript--DOM操作表格及样式(21)
一 操作表格 // <table>标签是HTML中结构最为复杂的一个,我们可以通过DOM来创建生成它,或者HTMLDOM来操作它; // 使用DOM来创建表格; var table = d ...
- web自动化开发环境配置详解
1.安装 nodejs Grunt和所有grunt插件都是基于nodejs来运行的, https://nodejs.org/ 安装完成之后在终端 node -v 查看安装版本 2.安装 grunt-C ...
- 【读书笔记】iOS-iOS6 Passbook应用开发
Passbook 是iOS6的新功能,只能在iPhone和iPod touch设备中使用,它可以帮助管理商家发放的电子会员卡,积分卡,优惠券等. 一,Passbook 与 Pass. Passbook ...
- vue 自定义组件的自定义属性
<auto-com :value="value"></auto-com> //带 : 的属性传入的是动态的值 <auto-com value=&quo ...
- 安装vs2008出现MSI returned error code 1603的错误的解决
作者:朱金灿 来源:http://blog.csdn.net/clever101 在win7 64位旗舰版上安装vs2008 ,一直停留在下面页面: 最后错误日志是: [12/12/16,15:39: ...
- python 日志打印之logging使用介绍
python 日志打印之logging使用介绍 by:授客QQ:1033553122 测试环境: Python版本:Python 2.7 简单的将日志打印到屏幕 import logging lo ...
- oracle学习之pl/sql使用==转载
PLSQL循序渐进全面学习教程(全):https://blog.csdn.net/spark998/article/details/2065269
- windows10如何打开vhd文件
本人电脑安装了Visual Studio 2017,但是由于项目需求需要Core SDK(2.0)的版本支持,也就是2017最新版.所以现在需要利用visual Studio 2017最新版本的安装包 ...
- .NET笔试题集(五)
转载于:http://www.cnblogs.com/ForEvErNoME/archive/2012/09/15/2684938.html 1.什么是受管制的代码? 答:unsafe:非托管代码.不 ...
- Oracle EBS AP 取消付款
--取消付款 created by jenrry 20170425 declare l_return_status varchar2(50); l_msg_count number; l_msg_da ...