zoukankan      html  css  js  c++  java
  • UVa 357 Let Me Count The Ways

    又是硬币型的。。

    虽然通过了,还有几个疑问:

    1. 题目中说

      The input will consist of a set of numbers between 0 and 30000 inclusive, one per line in the input file. ,

       难道不包括30000吗? 输入30000时AC的程序结果是负值(将long long int 改为unsigned long long int可以解决)。

    2. 使用dev c++输出时出现错误:

      There are 6 ways to produce 0 cents change.
      There are 4 ways to produce 0 cents change.

       怀疑是编译器造成的,尚无确定结论。

     1 /* 357 - Let Me Count The Ways */
    2 # include <stdio.h>
    3
    4 const int coin[] = {0,1,5,10,25,50};
    5
    6 long long int f[30005][6];
    7
    8 long long dp(int m, int i);
    9
    10 int main()
    11 {
    12 int n;
    13 long long int t;
    14
    15 while (~scanf("%d", &n))
    16 {
    17 t = dp(n, 5);
    18 if (t == 1) printf("There is only 1 way to produce %d cents change.\n", n);
    19 else printf("There are %lld ways to produce %d cents change.\n", t, n);
    20 }
    21
    22 return 0;
    23 }
    24
    25 long long int dp(int m, int i)
    26 {
    27 int k;
    28 if (f[m][i] > 0) return f[m][i];
    29 if (m == 0 || i <= 1) return f[m][i] = 1;
    30 for (k = 0; k <= m; k += coin[i])
    31 f[m][i] += dp(m-k, i-1);
    32 return f[m][i];
    33 }



  • 相关阅读:
    .net基础学java系列(一)视野
    技术栈
    Apollo(阿波罗)携程开源配置管理中心
    .NET 动态调用WCF
    RPC 工作原理
    ServiceStack 简单使用
    PRC 框架选择
    栈vs堆,最详细的对比
    使用SuperSocket打造逾10万长连接的Socket服务
    开源项目练习EF+jQueryUI前后端分离设计
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2429856.html
Copyright © 2011-2022 走看看