hdu2069 Coin Change

来源:互联网 发布:编程解决鸡兔同笼 编辑:程序博客网 时间:2024/06/07 02:49

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
思路
二维母函数,由于硬币总数<=100,还需要开辟一个数组记录用的硬币数

/*************************************************************************    > File Name: hdu2069.cpp    > Author:gens_ukiy     > Mail:     > Created Time: 2016年11月30日 星期三 16时45分06秒 ************************************************************************/#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<set>#include<list>#include<map>using namespace std;#define rep(i,a,b) for(int i=(a);i<=(b);(i++))#define inf 0x3f3f3f#define ll long long#define maxn 255int c1[maxn][105],c2[maxn][105],re[maxn];int main(){    int n;    int coin[5]={1,5,10,25,50};    memset(c1,0,sizeof(c1));    memset(c2,0,sizeof(c2));    c1[0][0]=1;    rep(i,0,4)    {        rep(j,0,250)            for(int k=0;k*coin[i]+j<=250;k++)                for(int p=0;k+p<=100;p++)                    c2[j+k*coin[i]][p+k] += c1[j][p];        rep(j,0,250)                rep(p,0,100)        c1[j][p]=c2[j][p],c2[j][p]=0;    }    rep(i,1,250)        rep(j,0,100)            re[i] += c1[i][j];    re[0]=1;    while(cin>>n)        printf("%d\n",re[n]);    return 0;}
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 老师上课发现学生课上自慰怎么办 生完孩子腿粗屁股大怎么办 产后42天检查子宫偏大怎么办 崇拜瑜伽老师喜欢上他了怎么办 练瑜伽下不了腰贴不住腿怎么办 吃母乳宝宝吸的奶头疼怎么办 孩子吃奶把奶头咬破了怎么办 奶头边上让孩子咬破了吃奶疼怎么办 腰部受过伤久坐缓解腰疼怎么办 小孩八个月了还在软得很怎么办 产后第三天乳房胀痛有硬块怎么办 怀孕七个多月了胎位不正怎么办 怀孕6个月梅毒1:4怎么办 怀孕了胃酸胃涨吐酸水怎么办 怀孕了胃酸胃胀吐酸水怎么办 练瑜伽大腿外侧扭筋了怎么办 膝盖运动时疼痛睡觉不疼怎么办 在农村里床上老是有小蜈蚣该怎么办 瑜伽垫晒太阳后散发的甲醛怎么办 杯子盖上的皮垫子掉了漏水怎么办 20个月宝宝天天晚上不睡觉怎么办 八个月大小孩天天晚上不睡觉怎么办 如果开了光的貔貅不要了要怎么办 刚岀生的婴儿长得太快怎么办 呼市去办牌照时没有牌照怎么办 宾馆发现隐藏的摄像头怎么办报警吗 拍拍贷律师函寄到家里了怎么办 欠了拍拍贷本息一万多了怎么办 把人偷小孩的人贩子打死了怎么办 怀孕3个月没有胎心怎么办 社保局打印关系转移信封之后怎么办 长裙变装外出被发现了怎么办 超变陀螺怎么绳子拉不出来怎么办 梦幻诛仙传说时间得不到东西怎么办 夹在强势母亲和强势老公中间怎么办 工作调动校长总拖着不盖章怎么办 宝贝在妈妈肚子里发育慢怎么办 领导安排你负责一次讲座你怎么办 雷蛇北海巨妖耳机有回音怎么办 手机直播声卡有杂音有回音怎么办 大班见到陌生人入园怎么办安全教案