Coin Change

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10590    Accepted Submission(s): 3535

Problem Description
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.

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.

 
Input
The input file contains any number of lines, each one consisting of a number ( ≤250 ) for the amount of money in cents.
 
Output
For each input line, output a line containing the number of different ways of making changes with the above 5 types of coins.
 
Sample Input
11
26
 
Sample Output
4
13
 
Author
Lily
 
Source
 

思路: 此题可以采取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的更多相关文章

  1. [LeetCode] Coin Change 硬币找零

    You are given coins of different denominations and a total amount of money amount. Write a function ...

  2. HDOJ 2069 Coin Change(母函数)

    Coin Change Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 2069 Coin Change

    Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...

  4. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

  5. JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)

    JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划)     B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...

  6. C - Coin Change (III)(多重背包 二进制优化)

    C - Coin Change (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu ...

  7. Coin Change (IV) (dfs)

    Coin Change (IV) Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu [Subm ...

  8. Coin Change (II)(完全背包)

                                                               Coin Change (II) Time Limit: 1000MS   Mem ...

  9. [LeetCode] Coin Change 2 硬币找零之二

    You are given coins of different denominations and a total amount of money. Write a function to comp ...

  10. UVA.674 Coin Change (DP 完全背包)

    UVA.674 Coin Change (DP) 题意分析 有5种硬币, 面值分别为1.5.10.25.50,现在给出金额,问可以用多少种方式组成该面值. 每种硬币的数量是无限的.典型完全背包. 状态 ...

随机推荐

  1. Neo4j 查询某标签节点个数语句 删除某标签全部节点语句

    查询:MATCH (n:标签名) RETURN count(n) 删除:MATCH (n:标签名) DELETE n

  2. Java归去来第3集:Eclipse中给动态模块升级

    一.前言 如果还不了解剧情,请返回第2集的剧情          Java归去来第2集:利用Eclipse创建Maven Web项目 二.开始升级动态模块 2.1:查看原来的版本 我们先来看看Ecli ...

  3. Github上Stars最多的53个深度学习项目,TensorFlow遥遥领先

    原文:https://github.com/aymericdamien/TopDeepLearning 项目名称 Stars 项目介绍 TensorFlow 29622 使用数据流图计算可扩展机器学习 ...

  4. web自适应手机浏览器的宽度

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...

  5. OPENGL: WHY IS YOUR CODE PRODUCING A BLACK WINDOW?

      Introduction One of the most common problems for novice, and sometimes experienced, OpenGL program ...

  6. c++ 中const的使用

    在c++中.const是这么一个东西:假设你希望可以有一些东西是别人不能改动的,这个时候const就起作用了. const 在使用情况例如以下: a.修饰常量 const int a; int con ...

  7. 数据结构 - 2-路插入排序 具体解释 及 代码(C++)

    2-路插入排序 具体解释 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24267679 2-路插入排序的思想非常有意思 ...

  8. XE6入门(二)项目中的文件

    XE6中项目文件为DPR,查看方法请参考一下以前写过的博文: "Delphi项目构成之项目文件DPR" 项目文件DPR 通过主菜单[Project | View Source],就 ...

  9. js获取对象值的方式

    js获取对象值的方式 var obj = {abc:"ss",nn:90}; var v1 = obj.abc;//使用点的方式 var v2 = obj["abc&qu ...

  10. oracle sqlldr使用(导入速度快,但对数据本身的处理功能弱)

    oracle sqlldr使用(导入速度快,但对数据本身的处理功能弱) 博客分类: DB.Oracle OracleSQL  sqlload.cmd pause sqlldr user/pass@tn ...