题目链接: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. 安装phpredis

    1.下载安装包 https://github.com/nicolasff/phpredis/archive/2.2.5.tar.gz 2.解压到~目录 tar -xvf phpredis-2.2.5. ...

  2. MD5 校验文件

    https://blog.csdn.net/wudishine/article/details/42466831 MD5.h #ifndef MD5_H #define MD5_H #include ...

  3. oracle--循环PL/SQL--demo1---

    --简单的条件判断if–then --编写一个过程,可以输入一个雇员名,如果该雇员的工资低于2000,就给该员工工资增加10%. create or replace procedure sp_pro6 ...

  4. hibernate HQL查询

    hql(都要在事务中完成)session.beginTransaction();session.getTransaction().commit(); session.beginTransaction( ...

  5. CentOS 7 配置 ISCSI 服务器

    一.服务器配置 1.安装配置软件: yum install targetcli -y 2.进入配置界面: targetcli ,并进行如下配置: 1) /backstores/block create ...

  6. Flask03 路由控制(转换器)、反转、请求方法控制

    1 提出问题 如何实现前端传过去的路径时动态的(即:多个url对应一个url视图函数) 例如: 浏览器中输入 http://127.0.0.1:5000/test/good/ 或者 http://12 ...

  7. Hive中SELECT TOP N的方法(order by与sort by的区别)

    我想说的SELECT TOP N是取最大前N条或者最小前N条. Hive提供了limit关键字,再配合order by可以很容易地实现SELECT TOP N. 但是在Hive中order by只能使 ...

  8. 第六课 ROS的空间描述和变换

    1.空间描述与变换 有两个坐标系A和B,B坐标系中有一个点P,如何把B坐标系中的P映射到A坐标系呢,这就涉及到空间描述与变换, 先看一下旋转矩阵: 上面中间的行向量中的元素表示在B坐标系当中的元素用A ...

  9. 使用VS Code配合Remote Development插件连接远程服务器(Mac/Linux+Windows) | Using VS Code with Remote Development Connect to Remote Server (Mac/Linux+Windows)

    最新版VS Code(2019年6月)出了一系列新的插件,包括Remote Development,Remote SSH等,使得用户可以使用VS Code远程连接服务器写代码,方便了协同工作.具体配置 ...

  10. Apple Swift中文入门教程【转发】

    1   简介 今天凌晨Apple刚刚发布了Swift编程语言,本文从其发布的书籍<The Swift Programming Language>中摘录和提取而成.希望对各位的iOS& ...