Coin Change

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 16032    Accepted Submission(s): 5441

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

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dp[500][600];
int num[1000];
int coin[6]={0,1,5,10,25,50};
void getnum()
{
memset(dp,0,sizeof(dp));
memset(num,0,sizeof(num));
dp[0][0]=1;
for(int i=1;i<=5;i++)
{
for(int j=0;j<=250;j++)//货币总面额不超过250
{
for(int k=0;k<100;k++)//硬币总数不超过100个
{
if(coin[i]+j<=250)
dp[coin[i]+j][k+1]+=dp[j][k];//当前货币总面值为j,分成k个硬币
else
break;
}
}
}
for(int i=0;i<=250;i++)
{
for(int j=0;j<=100;j++)
num[i]+=dp[i][j];
}
}
int main()
{
int n;
getnum();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",num[n]);
}
}

hdoj--2069--Coin Change(动态规划)的更多相关文章

  1. HDOJ 2069 Coin Change(母函数)

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

  2. HDU 2069 Coin Change

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

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

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

  4. 题解报告:hdu 2069 Coin Change(暴力orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Problem Description Suppose there are 5 types of ...

  5. HDU 2069 Coin Change(完全背包变种)

    题意:给你5种银币,50 25 10 5 1,问你可以拼成x的所有可能情况个数,注意总个数不超过100个 组合数问题,一看就是完全背包问题,关键就是总数不超过100个.所有我们开二维dp[k][j], ...

  6. hdu2069(Coin Change)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069 Coin Change Time Limit: 1000/1000 MS (Java/Other ...

  7. [LeetCode] Coin Change 硬币找零

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

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

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

  9. LeetCode OJ 322. Coin Change DP求解

    题目链接:https://leetcode.com/problems/coin-change/ 322. Coin Change My Submissions Question Total Accep ...

  10. [LeetCode] 322. Coin Change 硬币找零

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

随机推荐

  1. WinForm中DataReader绑定到DataGridView的两种方法

    在WinForm中,DataReader是不能直接绑定到DataGridView的,我想到了用两种方法来实现将DataReader绑定到DataGridView. SqlCommand command ...

  2. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本3(九)

    不多说,直接上干货! 下面,是版本1. Hadoop MapReduce编程 API入门系列之挖掘气象数据版本1(一) 下面是版本2. Hadoop MapReduce编程 API入门系列之挖掘气象数 ...

  3. Linux下实现视频读取

    V4L(video4linux是一些视频系统,视频软件.音频软件的基础,经常时候在需要采集图像的场合,如视频监控,webcam,可视电话,经常使用在embedded linux中是linux嵌入式开发 ...

  4. 搭建eclipse的安卓开发环境(eclipse+jdk+adt+sdk)

    学校暑期大作业让用安卓写一个app,有两种方案(android stduio+sdk和eclipse+jdk+adt+sdk)折腾了几天发现还是后者好用,但是安装环境和下载真的是去了半条命,(不过由于 ...

  5. 设计模式(C++实现)--一句话总结

    原文链接:http://blog.csdn.net/LCL_data/article/details/12117349 按照目的来分,设计模式可以分为创建型模式.结构型模式和行为型模式. 按照目的来分 ...

  6. 那些年 IE 下踩过的坑

    1年过去了,换了一个不用兼容IE8一下浏览器的工作了! 1.:before,:after(伪类) 所有主流浏览器都支持 :before 选择器. 注释:对于 IE8 及更早版本中的 :before,必 ...

  7. Kafka学习笔记(3)----Kafka的数据复制(Replica)与Failover

    1. CAP理论 1.1 Cosistency(一致性) 通过某个节点的写操作结果对后面通过其他节点的读操作可见. 如果更新数据后,并发访问的情况下可立即感知该更新,称为强一致性 如果允许之后部分或全 ...

  8. Mac 查看 剪贴板/剪切板/粘贴板 内容与格式

    命令行形式 osascript -e 'clipboard info' GUI 形式 Finder->编辑->显示剪贴板 图示:

  9. 如何选择优动漫PAINT版本?是个人版还是EX版

    优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,它是一款功能强大的动漫绘图软件,适用于个人和专业团队创作,分为个人版和EX版.搭载了绘制漫画和插画所需的所有功能 ...

  10. div与div之间的拖拽

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...