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. C-概览

    1.贝尔实验室的Dennis Ritchie在1972年开发了C语言,C来自于Ken Thompson的B语言.当时Ritchie正与 Thompson一起设计UNIX操作系统. 2.C是面向过程的编 ...

  2. WindowsNT设备驱动程序开发基础

    一.背景介绍 1.1WindowsNT操作系统的组成1.1.1用户模式(UserMode)与内核模式(KernelMode) 从Intel80386开始,出于安全性和稳定性的考虑,该系列的CPU可以运 ...

  3. DataGridView属性设置汇总

    1.标题列居中 外观  ColumnHeadersDefaultCellStyle - Alignment - MiddleCenter 2.表格内容居中 外观  DefaultCellStyle - ...

  4. STL:使用string、vector、complex和limits

    (有少量修改!)使用到了STL的算法库: #include<algorithm> #include<vector> //属于STL库 模板库 写库的人为了和标准C和C++库区分 ...

  5. BigDecimal,注解

    BigDecimal 问题重现 今天在干活的途中,发现一个很坑爹的问题,让我来复现下问题: 从上游接口获得的余额,对于为0的,做了判断 BigDecimal a = new BigDecimal(ac ...

  6. mysql 最大连接数

    方式一: 一次性修改  服务重启后还原 查看  show variables like 'max_connections%'; 修改 set GLOBAL max_connections=1024; ...

  7. openlayers5学习笔记-001

    tmp.initPoint = function (items) { //初始化所有农户点坐标,聚合 var count = items.length; var features = new Arra ...

  8. SaltStact自动化运维工具02

     Grains基础:• Grains是saltstack最重要的组件之一• 存储minion端的基本信息,这些信息一般都是静态的,如CPU.内核.操作系统等• Grains存储在minion本地• 管 ...

  9. bzoj 1191: [HNOI2006]超级英雄Hero 网络流_残量网络

    题目描述: 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的 多少获得不同数目的奖品或奖金.主持人问题准备了若干道题目,只有当选手正确回答一道题后 ...

  10. 【udacity】机器学习-波士顿房价预测

    import numpy as np import pandas as pd from Udacity.model_check.boston_house_price import visuals as ...