题目链接: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. 使用TortoiseGit来访问GitHub

    因为以前一直在用TSVN, 对其界面操作比较熟悉. 因此,决定不用Git Gui而是用TortoiseGit来访问GitHub. 安装TortoiseGit成功后, 1.运行PuTTY Key Gen ...

  2. Azure blob Storage Snapshot

    用户虚拟机硬盘的备份是客户在部署云应用中是一个非常重要的部分. 目前有多种平台的备份方法: 捕获镜像:可以采用Capture的方式(powershell命令为Save-AzureVMImage)捕获虚 ...

  3. js 函数定义的两种方式以及事件绑定(扫盲)

    一.事件(例如:onclick)绑定的函数定义放在jsp前面和放后面没影响 二. $(function() { function func(){}; }) onclick通过如下方式绑定事件到jsp中 ...

  4. linux日常管理-rsync后台服务方式-1

    rsync的另外一种方式,写一个配置文件,放在etc下,通过一个命令启动他,它会监听一个端口,在客户端和服务端进行通信. 远程机器的配置文件 IP是192.168.1.117 配置文件的名字,写成这个 ...

  5. linux命令-bzip2压缩

    gzip和bzip2 都是压缩命令  区别是压缩算法不一样  一般bzip2压缩的效率高  都不能压缩目录 bzip2 压缩 [root@wangshaojun ~]# bzip2 install.l ...

  6. Java 数据类型间的相互转化

    Java中常见基本数据类型包括(String除外[引用]) Date(int year,int month,int day,int hour,int minute,int sec); String 格 ...

  7. C语言学习笔记--struct 和 union关键字

    1.struct关键字 C 语言中的 struct 可以看作变量的集合struct中的每个数据成员都有独立的存储空间. 结构体与柔性数组 (1)柔性数组即数组大小待定的数组 (2)C 语言中可以由结构 ...

  8. Material使用09 MdCheckboxModule、MdMenuModule、MdTooltipModule

    1 MdCheckboxModule的使用 md-checkbox 实现的功能和  <input type="checkbox">  相同,只不过 md-checkbo ...

  9. 20、BLAST比对及结果介绍

    1.formatdb -i /share/nas1/huangt/project/IsoSeq/BMK170104-E545-03-a/Analysis_T01/MoveRebundant/T01/c ...

  10. vue.js基础学习(1)

    一:v-cloak:解决浏览器闪烁,编译过程中不会显示,直到编译结束才显示. 用法:[v-cloak] { display: none;} <div v-cloak> {{ message ...