Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C++ Data Structures and Algorithm Design Principles

You're reading from   C++ Data Structures and Algorithm Design Principles Leverage the power of modern C++ to build robust and scalable applications

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher
ISBN-13 9781838828844
Length 626 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Anil Achary Anil Achary
Author Profile Icon Anil Achary
Anil Achary
John Carey John Carey
Author Profile Icon John Carey
John Carey
Payas Rajan Payas Rajan
Author Profile Icon Payas Rajan
Payas Rajan
Shreyans Doshi Shreyans Doshi
Author Profile Icon Shreyans Doshi
Shreyans Doshi
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

About the Book 1. Lists, Stacks, and Queues FREE CHAPTER 2. Trees, Heaps, and Graphs 3. Hash Tables and Bloom Filters 4. Divide and Conquer 5. Greedy Algorithms 6. Graph Algorithms I 7. Graph Algorithms II 8. Dynamic Programming I 9. Dynamic Programming II 1. Appendix

Subset Sum Problem

Imagine that you are implementing the logic for a digital cash register. Whenever a customer needs change, you would like to display a message that tells the cashier whether or not the money currently in the register can be combined in some way so that its sum is equal to the amount of change required. For example, if a product costs $7.50 and the customer pays $10.00, the message would report whether the money in the register can be used to produce exactly $2.50 in change.

Let's say that the register currently contains ten quarters (10 x $0.25), four dimes (4 x $0.10), and six nickels (6 x $0.05). We can easily conclude that the target sum of $2.50 can be formed in the following ways:

10 quarters                    -> $2.50

9 quarters, 2 dimes, 1 nickel -> $2.25 + $0.20 + $0.05

9 quarters, 1 dime, 3 nickels -> $2.25 + $0.10 + $0.15

9 quarters, 5 nickels   ...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime