Coin Change

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10924 Accepted Submission(s): 3669

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
 

母函数

import java.io.*;
import java.util.*;
public class Main {
public int money[]={1,5,10,25,50};
public int M=250;
public int patten[][]=new int[M+1][M+1];
public static void main(String[] args) {
new Main().work();
}
public void work(){
init();
Scanner sc=new Scanner(new BufferedInputStream(System.in));
while(sc.hasNextInt()){
int n=sc.nextInt();
if(n==0){
System.out.println(1);
}
else{
int sum=0;
for(int i=1;i<=n&&i<=100;i++){
sum+=patten[i][n];
}
System.out.println(sum);
}
}
}
public void init(){
patten[0][0]=1;
for(int i=0;i<5;i++){
for(int j=1;j<=100;j++){
for(int k=money[i];k<=M;k++){
patten[j][k]=patten[j][k]+patten[j-1][k-money[i]];
}
}
}
}
}

HDU 2069 Coin Change的更多相关文章

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

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

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

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

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

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

  4. HDOJ 2069 Coin Change(母函数)

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

  5. hdu2069(Coin Change)

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

  6. [LeetCode] Coin Change 硬币找零

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

  7. hdu 2069 限制个数的母函数(普通型)

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

  8. UVA 674 Coin Change(dp)

    UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/ ...

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

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

随机推荐

  1. 基础-函数3(IIFE立即执行函数)

    参考链接: http://benalman.com/news/2010/11/immediately-invoked-function-expression/#iife http://segmentf ...

  2. python入门笔记第一天

    查询acsii命令 ord(‘A’) 导入模块python执行系统命令显示文件.查找文件方法1import osa = os.popen('目标').read()a 解释output = os.pop ...

  3. Bag of Words/Bag of Features的Matlab源码发布

    2010年11月19日 ⁄ 技术, 科研 ⁄ 共 1296字 ⁄ 评论数 26 ⁄ 被围观 4,150 阅读+ 由于自己以前发过一篇文章讲bow特征的matlab代码的优化的<Bag-Of-Wo ...

  4. MFC 之ActiveX控件学习

    本文将介绍ActiveX控件的应用与工作原理,读者可以把ActiveX控件看成一个极小服务器的应用程序,它不能独立运行,必须要嵌入到容器程序中与容器一起运行,就像电脑主机中的显卡,它自己在电脑硬件系统 ...

  5. java项目创建和部署

    http://www.cnblogs.com/nexiyi/archive/2012/12/28/2837560.html http://dead-knight.iteye.com/blog/1841 ...

  6. bzoj 1034: [ZJOI2008]泡泡堂BNB 貪心

    1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1398  Solved: 727[Submit][Sta ...

  7. html5自定义标签选择器

    * E[attr]:只使用属性名,但没有确定任何属性值 * E[attr="value"]:指定属性名,并指定了该属性的属性值.必须和元素的属性完全匹配 * E[attr~=&qu ...

  8. 框架中的HTML DOM Event 对象

    js中的this上下文会因事件而转换成html dom对象. 所以就有这样获取当前触发事件的dom对象: window.event.srcElement || window.event.target; ...

  9. 吉哥系列故事——完美队形II

    hdu4513:http://acm.hdu.edu.cn/showproblem.php?pid=4513 题意:给以一个序列,然后让你求一个最长回文序列的长度,这个序列的从左到最中间那个数是不降的 ...

  10. 浅谈.Net和Java互相调用的三种方式

    在很多的大型系统开发中,开发工具往往不限制于同一种开发语言,而是会使用多种开发语言的混合型开发.目前Java和.Net都声称自己占85%的市场份 额,不管谁对谁错,Java和.Net是目前应用开发的两 ...