Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <set>
- //Just a brute force recursive solution, to be used as a first step in finding the optimal solution, i.e. by adding memoization
- //and then possibly flipping into a table-based bottom-up solution
- namespace with_multiset
- {
- void make_change (int amount, std::vector<int> const &coins, std::set<std::multiset<int>> &changes, std::multiset<int> partial = {})
- {
- if (amount == 0)
- {
- changes.insert(partial);
- return;
- }
- int res = 0;
- for (auto c : coins)
- {
- if (c <= amount)
- {
- auto where = partial.insert(c);
- make_change(amount - c, coins, changes, partial);
- partial.erase(where);
- }
- }
- }
- std::set<std::multiset<int>> make_change (int amount, std::vector<int> const &coins)
- {
- std::set<std::multiset<int>> changes;
- make_change(amount, coins, changes);
- return changes;
- }
- }//namespace with_multiset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement