-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletMeCountTheWays.cpp
49 lines (42 loc) · 959 Bytes
/
letMeCountTheWays.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("letMeCountTheWays.in");
ofstream fout("letMeCountTheWays.out");
int main()
{
vector<int> c = {1, 5, 10, 25, 50};
vector<long long> dp(30001, 0);
dp[0] = 1;
for (int j = 0; j <= 4; ++j)
{
for (int i = 1; i <= 30000; ++i)
{
if (i >= c[j])
{
dp[i] += dp[i - c[j]];
}
}
}
int in;
while (fin >> in)
{
if (dp[in] == 1)
{
fout << "There is only 1 way to produce " << in << " cents change.\n";
}
else
{
fout << "There are " << dp[in] << " ways to produce " << in << " cents change.\n";
}
}
return 0;
}