zoukankan      html  css  js  c++  java
  • hdu 2069 Coin Change 解题报告

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2069

    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
    本题不知道怎么说,开始用母函数做,一直 wa,与网上牛人打的表对比,发现前100的都是对的,原因是硬币不能超过100.
    没办法就选择了暴力了, 然后还居然A了····
    wa的代码:
    #include <stdio.h>
    #include
    <stdlib.h>
    #define Max 20000
    int c1[Max], c2[Max], c3[Max], c4[Max], c5[Max];
    int main()
    {
    int n;
    while( scanf( "%d", &n ) != EOF )
    {
    for( int i=0; i<Max; ++i )
    c5[i]
    =c4[i]=c1[i]=c2[i]=c3[i]=0;
    for( int i=0; i<=n; ++i ) //初始化系数为 1 ( 1+x + +x^2 + x^3·· )
    {
    c1[i]
    =1;
    }
    for( int i=0; i<=n; ++i )
    {
    for( int j=0; i+j<=n; j+=5 )
    {
    c2[i
    +j]+=c1[i];
    }
    }
    for( int i=0; i<=n; ++i )
    {
    for( int j=0; i+j<=n; j+=10 )
    {
    c3[i
    +j]+=c2[i];
    }
    }
    for( int i=0; i<=n; ++i )
    {
    for( int j=0; i+j<=n; j+=25 )
    {
    c4[i
    +j]+=c3[i];
    }
    }
    for( int i=0; i<=n; ++i )
    {
    for( int j=0; i+j<=n; j+=50 )
    {
    c5[i
    +j]+=c4[i];
    }
    }
    printf(
    "%d\n", c5[n] );
    }
    return 0;
    }

      ac的代码:

    #include<stdio.h>
    int main()
    {
    int a,b,c,d,e,count,n;
    while(scanf("%d",&n)!=EOF)
    {
    count
    =0;
    for(a=0;a<=n;a++)
    for(b=0;5*b<=n-a;b++)
    for(c=0;10*c<=n-a-5*b;c++)
    for(d=0;25*d<=n-a-5*b-10*c;d++)
    {
    e
    =n-a-5*b-10*c-25*d;
    if(e%50==0&&a+b+c+d+e/50<=100)count++;
    }
    printf(
    "%d\n",count);
    }
    }

      

  • 相关阅读:
    从0到1构建适配不同端(微信小程序、H5、React-Native 等)的taro + dva应用
    一个基于Ionic3.x cordova的移动APP demo
    基于 MUI 构建一个具有 90 +页面的APP应用
    风清杨之Oracle的安装与说明
    浅析C#中的“==”和Equals
    window.open()的使用
    动态生成级联下拉框和多选框
    生成二维码的两种方式
    登录添加验证码校验
    oracle11g的安装以及配置
  • 原文地址:https://www.cnblogs.com/jian1573/p/2131317.html
Copyright © 2011-2022 走看看