HDU_2069 Coin Change(dfs)
2015-06-27 13:54
411 查看
题目请点我
题解:
钱币的问题,背包应该是能做的,但是用暴力dfs也过了。注意所有的钱币加起来不能超过100枚,被这里坑了,睡了一觉醒来把它A掉了。
代码实现:
题解:
钱币的问题,背包应该是能做的,但是用暴力dfs也过了。注意所有的钱币加起来不能超过100枚,被这里坑了,睡了一觉醒来把它A掉了。
代码实现:
#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #define MAX_C 110 #define MAX_M 255 #define LL long long using namespace std; int result; int money; int type[5] = {50,25,10,5,1}; int dfs(int num,int t,int sum); int main() { while( scanf("%d",&money) != EOF ){ result = dfs(money,0,0); printf("%d\n",result); } return 0; } int dfs(int num,int t,int sum){ if( t == 4 ){ if( sum+num <= 100 ){ return 1; } else{ return 0; } } int left = num; int tmp = 0; int times = sum; while( left >= 0 && times <= 100 ){ tmp += dfs(left,t+1,times); left -= type[t]; times++; } return tmp; }
相关文章推荐
- Win2003利用dfs(分布式文件系统)在负载均衡下的文件同步配置方案
- win2003分布式文件系统(dfs)配置方法[图文详解]
- win2003分布式文件系统及其部署 图文教程
- Hadoop2.6+jdk8的安装部署(1)——使用jar包安装部署【详细】
- Hadoop FS Shell
- DFS使用方法总结
- FastDFS注意事项
- 无忧技术带您预览DFS(分布式文件系统)管理控制台
- C 语言实现迷宫 DFS算法
- 一幅图弄清DFT与DTFT,DFS的关系
- HDFS---Namenode
- HDFS ---- Services startup
- POJ1523 SPF dfs
- poj1731 Orders dfs
- Surrounded Regions
- Binary Tree Zigzag Level Order Traversal,Restore IP Addresses,Word Search,Simplify Path
- ZOJ Problem Set - 1711 解题报告
- ZOJ Problem Set - 2412解题报告
- ZOJ Problem Set - 1457 解题报告
- Letter Combinations of a Phone Number