-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoinage.cpp
More file actions
39 lines (34 loc) · 1011 Bytes
/
coinage.cpp
File metadata and controls
39 lines (34 loc) · 1011 Bytes
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
// Author: btjanaka (Bryon Tjanaka)
// Problem: (HackerRank) coinage
// Title: Coinage
// Link: https://www.hackerrank.com/challenges/coinage/problem
// Idea: Brute force search over all possible amounts of each domination. The
// last dimension (the 1's) can be calculated instead of searched, so the search
// is only O(1000^3), which C++ handles.
// Difficulty: medium
// Tags: math, complete-search
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a, b, c, d;
cin >> t;
while (t--) {
cin >> n >> a >> b >> c >> d;
int tot = 0, sum = 0;
for (int i = 0; i <= d; ++i) {
sum = i * 10;
if (sum > n) break;
for (int j = 0; j <= c; ++j) {
sum = i * 10 + j * 5;
if (sum > n) break;
for (int k = 0; k <= b; ++k) {
sum = i * 10 + j * 5 + k * 2;
if (sum > n) break;
if (n - sum <= a) ++tot; // If the ones are okay, add to the answer.
}
}
}
cout << tot << '\n';
}
return 0;
}