An atm can only dispense values of $1, $5, $20, and $50. Return the number 
of unique ways that a $ amount of X can be tendered.
($1, $5) is distinct from ($5, $1)

Input: 4 Output: 1
Input: 6 Output: 3
Input: 100 Output: 954515231698

这题和Coin Change很像,只不过这题需要考虑顺序的问题。

Solution1:

用递归做。就像斐波那契数列那样。

public int atm(int x) {if (x <= 0)return x == 0 ? 1 : 0;return atm(x - 1) + atm(x - 5) + atm(x - 20) + atm(x - 100);
}

但是这样很多重复的计算,输入太大的话会栈溢出。所以我们可以考虑把中间结果保存起来。

Solution2:

public long tellMoneyCombinations(int money) {long[] f = new long[money+1];f[0] = 1;for(int i=1; i<=money; i++) {f[i] = f[i-1];if(i>=5) f[i]+=f[i-5];if(i>=20) f[i]+=f[i-20];if(i>=50) f[i]+=f[i-50];}return f[money];
}

Number of unique ways that ATM can tender相关推荐

  1. pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe)

    pandas使用nunique函数计算dataframe每个数据列的独特值的个数(count number of unique values in each column of dataframe) ...

  2. mysql unique count_MySQL - Count Number of Unique Values

    问题 If I have three columns: orderNumber, name, email and I would like to count how many unique email ...

  3. Dollar Dayz POJ - 3181(动态规划+大数高低位分离输出)

    题意:就是给出二个数N,和k,有1~k种钱币,每种都 是无限个,用这些种类的钱币可以组合成总钱N有多少种方式. 解题:这就是一个完全背包,把N看成容量,钱币的类型值为 花费和价值.与记录有多少种路径的 ...

  4. 插图 引用 同一行两个插图_数学身份的优雅LED插图

    插图 引用 同一行两个插图 by Chris Lam 克里斯·林(Chris Lam) 数学身份的优雅LED插图 (An elegant LED illustration of a mathemati ...

  5. UVA10338 Mischievous Children【组合数学】

    Adam's parents put up a sign that says "CONGRATULATIONS". The sign is so big that exactly ...

  6. bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(高精度完全背包)

    1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 599  Solved: 3 ...

  7. Dollar Dayz-完全背包+大数处理

    [题目] Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on ...

  8. leetcode63. Unique Paths II

    题目要求 Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. H ...

  9. Unique Paths II leetcode java

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

最新文章

  1. Crystal Reports中的字段
  2. JIPB:白洋组综述根系微生物组群落构建及其对植物适应性的贡献
  3. python学起来难吗-Python入门学习难吗,新手如何学习
  4. 【Flutter】Icons 组件 ( 加载 Flutter 内置的图标 | 材料设计图标完整展示 )
  5. 邀请函|WorkShop报名通道开启,来就送礼!
  6. intellij IDEA:Error : java 不支持发行版本xxx 的问题
  7. 吃冻梨对人会有什么好处?
  8. 从入门到入土:[SEED-Lab]MD5碰撞试验|MD5collgen实验|linux|Ubuntu|MD5 Collision Attack Lab|详细讲解
  9. AutoPlay Menu Builder入门教程
  10. php留言板开发功能,PHP实现基本留言板功能原理与步骤详解
  11. 【VScode】ubuntu系统的 VScode 调不出中文输入法
  12. 前端开发者必会的英语单词
  13. 论文阅读 (70):Exploring Self-attention for Image Recognition
  14. 直流电机开发笔记3—PI调节器的数字实现(代码/仿真)
  15. 帝都地铁隧道里的动态广告是什么原理?
  16. Springboot配置多个数据源
  17. iPhone手机使用:手机上面的App Store突然变成英文(iTunes也是英文),然后把英文还原成中文的方法
  18. kotlin类的成员变量 方法
  19. linux根据修改日期删除,在Linux下怎么一次性删除掉那些修改时间为指定日期的所有文件?...
  20. 24C01SC芯片介绍

热门文章

  1. 政务云迁移服务项目预算制定
  2. 分享一款免费下载音乐的软件
  3. BTC 查询交易明细信息
  4. Unity3d Platformer Pro 2D游戏开发框架使用教程
  5. enovia PLM : add new value to SPEO
  6. Python个人项目2 --------青蛙旅行项目
  7. Ubuntu 12.10 禁用来宾账户和远程登录
  8. php ajax 考试倒计时,基于Ajax技术实现考试倒计时并自动提交试卷
  9. 通达信macd接口指标
  10. 你都为美白缴过哪些智商税? | Alfred数据室