题目连接:357 - Let Me Count The Ways

题目大意:有5种硬币, 面值分别为1、5、10、25、50,现在给出金额,问可以用多少种方式组成该面值。

解题思路:和uva674是一样的, 只是上限不一样, 还有注意下输出。

#include <stdio.h>
#include <string.h>
const int N = 30005;
const int val[5] = {1, 5, 10, 25, 50}; long long cnt[N]; void Init() {
memset(cnt, 0, sizeof(cnt));
cnt[0] = 1;
for (int i = 0; i < 5; i++) {
for (int j = val[i]; j < N; j++)
cnt[j] += cnt[j - val[i]];
}
} int main() {
Init();
int n;
while (scanf("%d", &n) == 1) {
if (cnt[n] <= 1)
printf("There is only 1 way to produce %d cents change.\n", n);
else
printf("There are %lld ways to produce %d cents change.\n", cnt[n], n);
}
return 0;
}

最新文章

  1. 有时打开myeclipse,部署报错解决方案
  2. Debian7下初次尝试Nginx+Uwsgi部署Django开发环境
  3. http协议.md
  4. 深入浅出设计模式——解释器模式(Interpreter Pattern)
  5. TortoiseSVN 版本回滚
  6. svn 分支
  7. php相关学习资源
  8. 20141016--for 兔子
  9. 谈谈iOS中粘性动画以及果冻效果的实现
  10. Android 源码编译环境搭建(64位Ubuntu)各种依赖包安装
  11. nginx(ubuntu)设置别名访问目录
  12. 给你的网页添加一个随机的BGM
  13. AI要被祭天了!删Bug,删着删着把全部代码都删了
  14. c++入门之详细探讨类的一些行为
  15. 传输SO10 (SO10 Transport)
  16. LeetCode--443--压缩字符串(未看)
  17. 用 CSS 实现三角形与平行四边形
  18. hostapd作为radius服务器
  19. mysql中如何删除表上的索引?删除索引?
  20. springboot配置多数据源mongodb

热门文章

  1. Android新增API之AudioEffect中文API与应用实例
  2. Android创建与读取Excel
  3. BZOJ 1057: [ZJOI2007]棋盘制作( dp + 悬线法 )
  4. c语言数组初始化问题
  5. C++中用rand()和srand()产生随机数方法介绍
  6. Android解析Excel文档完整示例
  7. QQ登录-第三方SDK的接入总结
  8. ASIHTTPRequest-插件的使用
  9. NVelocity 实例
  10. 基于visual Studio2013解决面试题之1006判断升序