forked from maiquynhtruong/algorithms-and-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva147-dollars.cpp
32 lines (31 loc) · 934 Bytes
/
uva147-dollars.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
#include <bits/stdc++.h>
using namespace std;
#define N 30005
// global variables
bool debug = false;
double amount;
int denominations = 11;
long long dp[N];
int c[12] = {0, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000};
int main() {
ifstream cin("dollars.inp");
ios_base::sync_with_stdio(false);
cin.tie(NULL);
dp[0]=1;
for (int j = 1; j <= denominations; j++) {
for (int i = c[j]; i <= N; i++) {
dp[i] += dp[i-c[j]];
}
if (debug) {
for (int i = 1; i <= N; i++) cout << i << " ";
cout << "\n";
for (int i = 1; i <= N; i++) cout << dp[i] << " ";
cout << "\n";
}
}
cout << fixed << right << showpoint;
while (cin >> amount && amount > 0) {
unsigned int a = (unsigned) ((amount+0.001)*100);
cout << setw(6) << setprecision(2) << amount << setw(17) << dp[a] << "\n";
}
}