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. RabbitMQ(三) 集群配置

    RabbitMQ--集群配置 之前不管是搞Redis.SQL.Mongo还是其他的东西,一律都没说过集群要怎么搞,电脑实在是带不动.说透彻点就是懒,懒得搭也懒得写,今日深刻意识到错误,做学问是不能懒的 ...

  2. 运行Tomcat闪退问题,报的错误:Unsupported major.minor version 51.0

    在MyEclipse中运行tomcat,tomcat闪退并且报以下错误. java.lang.UnsupportedClassVersionError: org/apache/catalina/sta ...

  3. java网络编程之socket(1)

    网络编程是什么 网络编程的本质是两个设备之间的数据交换,当然,在计算机网络中,设备主要指计算机.数据传递本身没有多大的难度,不就是把一个设备中的数据发送给两外一个设备,然后接受另外一个设备反馈的数据. ...

  4. asp、asp.net、ado、ado.net各自区别和联系?

    asp.net与ado.net 的区别? asp.net是微软公司的.Net技术框架下的B/S(网页方向)框架技术.ado.net则是由asp.net编程语言编写的数据访问层的总括..说白了就是:as ...

  5. 【Oracle】搭建DG(DataGuard)

    操作系统:OEL 5.6 Oracle 版本:11.2.0.4.0 DataGuard规划说明 DATABASE_ROLE DB_NAME IPADDR Primary lgr 192.168.10. ...

  6. RAP开发入门-运行过程简析(三)

    今天通过标准的RAP程序来简单分析下RAP的启动过程 1.新建一个标准的rap plugin-in 项目: 得到的项目结构大概如下: run confi..->..add bundle(配置好b ...

  7. Ubuntu安装配置Python.pyDev

    一:安装ECLipse Eclipse官网下载软件tar包: 使用解压命令: sudo tar xzvf xxxxx.tar.gz -c /opt/ 创建快捷方式到桌面. 二:安装python-Num ...

  8. PhotoZoom如何使用调整大小配置文件

      众所周知PhotoZoom是一款图片无失真放大软件,所以在PhotoZoom中会有对尺寸大小调节功能.这里我们所要讲解的也是和尺寸调节等有关的功能——调整大小配置文件. 单击“调整大小配置文件.. ...

  9. python编写简单的html登陆页面(3)

    1  在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将静态分配数据,建立表格,存放学生信息 2  加载到静态数据 3  html的编写直接在表格里添加一组数据就行了 4  V ...

  10. 解决value toDF is not a member of org.apache.spark.rdd.RDD (spark2.1 )

    解决上述办法有两点: 1.两个import 需要放在 hiveCtx之后. val hiveCtx: SparkSession = SparkSession.builder.config(conf). ...