找零钱
来源:互联网 发布:网络安全法解读视频 编辑:程序博客网 时间:2024/04/29 14:53
有数组penny,penny中所有的值都为正数且不重复。每个值代表一种面值的货币,每种面值的货币可以使用任意张,再给定一个整数aim(小于等于1000)代表要找的钱数,求换钱有多少种方法。
给定数组penny及它的大小(小于等于50),同时给定一个整数aim,请返回有多少种方法可以凑成aim。
测试样例:
[1,2,4],3,3
返回:2
class Exchange {public: int countWays(vector<int> penny, int n, int aim) { // write code here vector<vector<int> > temp(n,vector<int>(aim+1)); for(int i=0; i<n; i++){ temp[i][0] = 1; } for(int j=0; j<=aim; j++){ if((j%penny[0]) == 0) temp[0][j] = 1; else temp[0][j] = 0; } for(int i=1; i<n; i++){ for(int j=1; j<=aim; j++){ if(j>=penny[i]) temp[i][j] = temp[i-1][j] + temp[i][j-penny[i]]; else temp[i][j] = temp[i-1][j]; } } return temp[n-1][aim]; }};
0 0
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱!
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 找零钱
- 动态归化 找零钱
- 找零钱问题
- Mac 环境下下配置opencv +python
- 同步执行与异步执行
- 定义 Model兼容python2.x和python3.x
- Stanford UFLDL教程 从自我学习到深层网络
- 欢迎使用CSDN-markdown编辑器
- 找零钱
- SpringMVC 运行机制
- 反转链表
- Stanford UFLDL教程 深度网络概览
- iOS远程推送介绍
- 第15周实践项目-直接插入排序
- Stanford UFLDL教程 栈式自编码算法
- android 屏幕适配核心概念与单位笔记
- Stanford UFLDL教程 微调多层自编码算法