题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069

Coin Change

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

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
 
题目大意:有50,25,10,5,1分的硬币,输入n,代表你要凑成的总数,要求你用这些硬币刚好凑成n,切硬币总个数不超过100
思路:这题超级大水,额,菜鸡的我以为很难很难,想了很久,绞尽脑汁也没有想出来,没想到直接5重循环就轻易解决了 ,很难受
看代码吧:
#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<ctype.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9;
const int maxn=+;
const int maxm=;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int ans=;
for(int i=;i*<=n;i++)
{
for(int j=;j*<=n;j++)
{
for(int k=;k*<=n;k++)
{
for(int l=;l*<=n;l++)
{
for(int m=;m<=n;m++)
{
if(i*+j*+k*+l*+m==n&&i+j+k+l+m<=)
ans++;
}
}
}
}
}
cout<<ans<<endl;
}
return ;
}

思路2:dp思想,dp[i][j]表示使得价值为i,用了 j  个硬币。  可以把硬币的价值用a[]存起来,dp[i][j]=dp[i][j]+dp[i-a[k]][j-1]

具体看代码:

#include<iostream>
#include<string.h>
#include<map>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<cmath>
#include<ctype.h>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
const ll mod=1e9;
const int maxn=+;
const int maxm=;
const int maxx=1e4+;
const ll maxe=+;
#define INF 0x3f3f3f3f3f3f
#define Lson l,mid,rt<<1
#define Rson mid+1,r,rt<<1|1
int a[]={,,,,};
int dp[maxn][];//dp[i][j]表示使得价值为i,用了j个硬币的种数
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(dp,,sizeof(dp));//初始化都为0
int ans=;
dp[][]=;
for(int i=;i<;i++)//5种价值的硬币
{
for(int j=;j<=;j++)//个数
{
for(int k=a[i];k<=n;k++)//最小为当前的a[i],一直遍历到n
{
dp[k][j]+=dp[k-a[i]][j-];//从上一个加上使用这一个的情况
}
}
}
for(int i=;i<=;i++) ans+=dp[n][i];
cout<<ans<<endl;
}
return ;
}

hdu2069(Coin Change)的更多相关文章

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

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

  2. Raft成员变化(Membership Change)

    我司高产作家唐刘老师的小猪佩奇版"深入浅出 Raft"第四弹来啦~~前几篇内容戳这里 ↓ 在猪爸爸的努力下,泥坑银行终于能高效正常的运作了,但猪爸爸一直比较担心海盗岛那边的网点,因 ...

  3. C#LeetCode刷题之#860-柠檬水找零(Lemonade Change)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4036 访问. 在柠檬水摊上,每一杯柠檬水的售价为 5 美元. 顾 ...

  4. LeetCode.860-卖柠檬水找零(Lemonade Change)

    这是悦乐书的第331次更新,第355篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第201题(顺位题号是860).在柠檬水摊上,每杯柠檬水的价格为5美元.客户站在队列中向 ...

  5. 项目管理知识框架PMBOK(文字版)

    项目管理知识框架PMBOK   项目整体管理[I](Integration) 1. 制定项目章程(Develop Project Charter) 2. 制定项目初步范围说明书(Develop Pre ...

  6. Dynamic CRM 2013学习笔记(二十七)无代码 复制/克隆方法

    前面介绍过二种复制/克隆方法:<Dynamic CRM 2013学习笔记(十四)复制/克隆记录> 和<Dynamic CRM 2013学习笔记(二十五)JS调用web service ...

  7. hdu 2069 Coin Change(完全背包)

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

  8. 【LeetCode】518. Coin Change 2 解题报告(Python)

    [LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目 ...

  9. UVA 674 Coin Change(dp)

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

随机推荐

  1. 牛客网字节跳动冬令营网络赛J Sortable Path on Tree —— 点分治

    题目:https://ac.nowcoder.com/acm/contest/296/J 用点分治: 记录了值起伏的形态,二元组 (x,y) 表示有 x 个小于号,y 个大于号: 因为小于号和大于号都 ...

  2. android开发 如何通过web服务器访问MYSQL数据库并且使其数据同步到android SQLite数据库?

    通过web服务器访问MYSQL数据库有以下几个过程: 1.在MySql下创建自己的数据库和自己的表单 2.连接数据库. 3.访问数据库 1.创建web工程 (服务器端) 在Myeclipse下新建一个 ...

  3. HUD1455:Sticks

    Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. Python:生成器表达式

    转于:http://www.cnblogs.com/liu-shuai/p/6098218.html 博主:刘-帅 简介: 生成器表达式并不真正的创建数字列表,而是返回一个生成器对象,此对象在每次计算 ...

  5. 【转】Pro Android学习笔记(二三):用户界面和控制(11):其他控件

    目录(?)[-] Chronometer计时器控件 倒计时CountDownTimer Switch控件 Space控件 其他控件 Android提供了很多控件,基本上都是view的扩展. Chron ...

  6. Java数组的基本讲解

    由于Java数组涵盖的内容比较多,这里从个人的角度对主要的内容进行相关的讲解. 如有不足,欢迎批评指正~ 1)Java数组是动态还是静态的啊?     Java语言是典型的静态语言,由此推断Java数 ...

  7. VisualGDB系列6:远程导入Linux项目到VS中

    根据VisualGDB官网(https://visualgdb.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指正. 本文介绍如何将Linux机器上的Linu ...

  8. C#使用NPOI读取电子表格Excel到DataGridView中

    上篇博文中已经介绍了如何写入Excel文件.这篇再介绍一下 如何从Excel中读取数据并保存到DataGridView中. 从Excel中读取数据并保存至DataGridView中,Excel文件第一 ...

  9. window下git,TortoiseGit安装,以及和github托管项目

    下载地址:http://msysgit.github.io/,安装时最好是先装git,再安装TortoiseGit. 一.git安装 1.第一步 2.第二步 3.第三步 4.第四步 5.第五步 6.第 ...

  10. GIT URI

    https://u3shadow@code.google.com/p/myandorid/