HDUOJ----Coin Change
Coin Change
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10590 Accepted Submission(s): 3535
For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent coin, or two 5-cent coins and one 1-cent coin, or one 5-cent coin and six 1-cent coins, or eleven 1-cent coins. So there are four ways of making changes for 11 cents with the above coins. Note that we count that there is one way of making change for zero cent.
Write a program to find the total number of different ways of making changes for any amount of money in cents. Your program should be able to handle up to 100 coins.
思路: 此题可以采取dfs,但是用分治法还是可以的,优化一下可以达到15ms......
在此贴出代码:
#include<iostream>
using namespace std;
int main()
{
int n,count;
int j,k,m,g,l;
while(cin>>n)
{
count=;
for( j=;j<=n/;j++) //
{
k=m=g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break; for( k=;k<=n/;k++) //
{
m=g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( m=;m<=n/;m++) //
{
g=l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( g=;g<=n/;g++) //
{
l=;
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
for( l=;l<=-j-k-m-g;l++) //
{
if(n==j*+k*+m*+g*+l)
{
count++;
break;
}
else
if(n<j*+k*+m*+g*+l)
break;
}
}
}
}
} cout<<count<<endl;
}
return ;
}
HDUOJ----Coin Change的更多相关文章
- [LeetCode] Coin Change 硬币找零
You are given coins of different denominations and a total amount of money amount. Write a function ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2069 Coin Change
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- UVA 674 Coin Change(dp)
UVA 674 Coin Change 解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...
- JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)
JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划) B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...
- C - Coin Change (III)(多重背包 二进制优化)
C - Coin Change (III) Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Coin Change (IV) (dfs)
Coin Change (IV) Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu [Subm ...
- Coin Change (II)(完全背包)
Coin Change (II) Time Limit: 1000MS Mem ...
- [LeetCode] Coin Change 2 硬币找零之二
You are given coins of different denominations and a total amount of money. Write a function to comp ...
- UVA.674 Coin Change (DP 完全背包)
UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...
随机推荐
- win7系统不能用telnet命令的两种解决方法
电脑专业人员对telnet命令都不陌生了,Telnet当成一种通信协议,在日常工作中,经常面对网络问题的人都会用到telnet命令,因为简单有效,可以帮助更快的找出问题.要是在使用过程中碰到win7纯 ...
- 说说最易被忽略的CSS强制性换行
一般情况下,元素拥有默认的white-space:normal(自动换行,PS:不换行是white-space:nowrap),当录入的文字超过定义的宽度后会自动换行,但当录入的数据是一堆没有空格的字 ...
- JS弹出层遮罩,隐藏背景页面滚动条细节优化
做过弹层组件的童鞋应该都考虑过特殊情况下取消页面滚动条,让其不能滚动,这样用户体验会好很多,当弹层内容超出屏幕展现范围的时候在弹层上面增加滚动条来查看全部内容. 一.去除滚动条方法给body添加ove ...
- Jquery怎么获取select选中项 自定义属性的值
Jquery如何获取select选中项 自定义属性的值?HTML code <select id="ddl" onchange="ddl_change(this)& ...
- 转: Xshell鼠标选中,终端立即中断(CTRL-C)的问题
转自: https://nkcoder.github.io/2014/05/05/xshell-select-interrupt-dict/ Xshell选中文字复制时中断 在Xshell中设置了“自 ...
- (文档)流媒体资源 Streaming Assets
Most assets in Unity are combined into the project when it is built. However, it is sometimes useful ...
- SNS网站的用户流失率怎么会高得如此惊人?
作者:黄绍麟 原51.com高管 用户典型的SNS体验 甲先生是个普通白领,白天工作使用互联网找资料连络客户,下班后回家偶而会上网闲逛.互联网是他日常接触的媒介,但是在他生命中这个东西并不显得特别重要 ...
- 一家VC支持企业的发展轨迹——了解每次融资后股权和期权的变化,以及股份是如何被稀释的【转载】
来源:ReachVc 该文是 ReachVC 上一篇文章,是某个投资公司副总裁的独立博客,文章写得不错.如果你是一个不太了解融资的创业者,那么本文将对你很有用.通过武林外传同福客栈的例子,了解每次融资 ...
- select/poll/epoll 对比
前两篇文章介绍了select,poll,epoll的基本用法,现在我们来看看它们的区别和适用场景. 首先还是来看常见的select和poll.对于网络编程来说,一般认为poll比select要高级一些 ...
- JS获取当前/指定URL参数
方法: 首先通过 document.location 获得当前访问网页的网址, 其次用 split 方法通过“?”把网址分为两部分. 如果网址中有参数(arrObj.length > 1) 再用 ...