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]; }
相关推荐
Tender任意端口扫描 多端口扫描 全能端口扫描 很好用!扫描很快!
20211202tender.7z
打印机TSC TTP-244 pro自带光盘映像文件,内含TSC Bar Tender2016标签设计软件、打印机驱动、说明书等。
GZRFPR – The tender offer and consent solicitation.pdf
kaj卡拉OK字幕:Love me tender;电子相册配音、字幕素材
They then extend this approach into specialised areas of procurement (including tender evaluation, outsourcing and Public-Private Partnerships), introducing technical risk assessment tools and ...
Observe the change of day and night: watch face that lit up the first rays of the sun, the glow of the sunset. Coral Clock 3D Screensaver v1.0 build 5 You - marine researcher who seeks the traces ...
Mastering Hyper-V is a practical, hands-on guide that will provide you with a number of clear, step-by-step exercises that help you understand how the products work and how you should go about them in...
现在就在将来运行: pull-me-tender选项pull-me-tender --helpUsage: pull-me-tender [options]Options:-h, --help output usage information-V, --version output the version number-a, --add-repositories [type...
执行您可以通过命令行提供所有凭据: ./bin/tender_discussions --tenderapikey YOUR_TENDER_API_KEY --tendersitename YOUR_TENDER_SITENAME --state pending --campfireaccount YOUR_CAMPFIRE_ACCOUNT --...
人力资源,英语人才适用。
open-tender-js该项目包含各种帮助程序功能,用于构建利用Open Tender API的电子商务应用程序。
open-tender与Open Tender开源Web应用程序一起使用的组件库。
tender-server
一个毕业设计网络招标系统实现了招标的业务逻辑内含了数据库sql server备份文件
简单生活,希望对大家有用!要觉得本资源有价值请分享给您的朋友,生活就是人来人往,分享越多!收获越多!作者:天天ASP家园
Tender,一个在 IRC 中运行敏捷风格站会的机器人招标是一个 IRC 机器人,可帮助您使用 IRC 为分布式团队运行站立会议。 #team:[11:00] < tender> Time for standup! It's in #standup#standup:[11:00] < ...
kz_tender_bo