Problem Summary
Given the volume of the big bottle (Q) and the volumes of P pails (p[1],p[2],…,p[P]), which are all integers, find the minimal sets of pails Farmer John needs to buy in order to measure out Q quarts of milk.
Solution
This problem can be solved using DP, but it would be relatively hard to analysis and implement.
Instead, I used iterative deepening depth-first search (IDDFS). It is very easy to understand, and the coding is quiet simple, too.
Code
|
|