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. FileStream读写文件流

    用FileStream 读取文件流并显示给文件内容 string p = @"C:\Users\Administrator\Desktop\1.txt"; FileStream f ...

  2. .net中String是引用类型还是值类型 以及 C#深层拷贝浅层拷贝

    http://www.cnblogs.com/yank/archive/2011/10/24/2204145.html http://www.cnblogs.com/zwq194/archive/20 ...

  3. JavaScript学习总结【7】、JS RegExp

    1.RegExp 简介 RegExp 即正则表达式(Regular Expression,在代码中常简写为 regex.regexp或RE/re/reg),就是使用单个字符串来描述.匹配一系列符合某个 ...

  4. php 接收 Android 传递的json 转 数组 问题

    过程:Android  拼接一个 json格式的数据 传值  ,php 接收 转为数组  json_decode   取值 json格式为:{"goods":{"1000 ...

  5. C语言实现五子棋简单功能

    /******************************************************************** C-4.29-1: 实现五子棋游戏 操作说明:用方向键或者& ...

  6. BZOJ 3569 DZY Loves Chinese II

    Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以修能. 遂降临于OI界,欲以神力而凌♂辱众生. 今Dzy有一魞歄图,其上 ...

  7. h.264 scanning process for transform coefficients

    宏块在经过变换.量化后,得到大小为4x4或者8x8的矩阵,矩阵中的数据被称为transform coefficient levels.这些level在后面会被用于熵编码,因此我们需要把矩阵按照一定顺序 ...

  8. Win8.1、Office2013一键激活工具

    Win8.1.Office2013一键激活工具 KMSpico V7.0 是一款激活Win8.Windows8.1和Office2013的工具,由国外网友heldigard基于KMSEmulator制 ...

  9. Java开发手册

    <Java开发手册> 基本信息 作者: 桂颖    谷涛    出版社:电子工业出版社 ISBN:9787121209161 上架时间:2013-8-12 出版日期:2013 年7月 开本 ...

  10. 关于IOS开发者账号一点总结

    经过查阅相关资料,我扼要总结了以下几点内容. 一.开发者账号类型 个人账号 99美金/年 公司账号 99 企业账号 299 教育账号 0 二.开发者账号有无比较 如果有: 可以真机测试 发布的应用可以 ...