UVA 357 Let Me Count The Ways

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA 357 Let Me Count The Ways相关的知识,希望对你有一定的参考价值。

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=293

Dynamic programming

注意overflow。

代码如下:

 1 //============================================================================
 2 // Name        : test.cpp
 3 // Author      : 
 4 // Version     :
 5 // Copyright   : Your copyright notice
 6 // Description : Hello World in C++, Ansi-style
 7 //============================================================================
 8 
 9 #include <iostream>
10 #include <math.h>
11 #include <stdio.h>
12 #include <cstdio>
13 #include <algorithm>
14 #include <string.h>
15 #include <cstring>
16 #include <queue>
17 #include <vector>
18 #include <functional>
19 #include <cmath>
20 #define SCF(a) scanf("%d", &a)
21 #define IN(a) cin>>a
22 #define FOR(i, a, b) for(int i=a;i<b;i++)
23 typedef long long Int;
24 using namespace std;
25 
26 int main()
27 {
28     int n;
29     int type[5] = { 1, 5, 10, 25, 50 };
30     Int ways[30005] = { 0 };
31     ways[0] = 1;
32     FOR(i, 0, 5)
33     {
34         FOR(j, type[i], 30005)
35         {
36             ways[j] += ways[j - type[i]];
37         }
38     }
39 
40     while (SCF(n)!=EOF)
41     {
42         if (ways[n] == 1)
43             printf("There is only 1 way to produce %d cents change.\n", n);
44         else
45             printf("There are %lld ways to produce %d cents change.\n", ways[n], n);
46     }
47     return 0;
48 }

 

以上是关于UVA 357 Let Me Count The Ways的主要内容,如果未能解决你的问题,请参考以下文章

UVA 1400 1400 - &quot;Ray, Pass me the dishes!&quot;(线段树)

UVA10474 Where is the Marble?排序

hdu 1004 let the ballon rise

357. Count Numbers with Unique Digits

357. Count Numbers with Unique Digits

357. Count Numbers with Unique Digits