You are likely familiar with the story of Henry an Liza and the hole in the bucket. Not too many people know what happened after Henry managed to fix the hole in his bucket. Liza, after the hole affair, was pretty upset with Henry. In an effort to get him to think, she had him fill a barrel with several different buckets. The barrel had to be filled exactly to the top by whole (or is that hole?) bucket quantities. Henry, being lazy, kept thinking about it until he could do it in the fewest buckets possible.
Sample Input A: Sample Input B: Sample Input C: 17 20 36 1 7 19 2 5 9 4 3 5 5 1 2 1 Sample Output A: Sample Output B: Sample Output C: 4 4 4
We start with Best[0]=0, and no explanation is needed for
that . The initial values of Best[i],
where i=1..N, are maximum values, and we will minimize
them later.
Let j be the size of the current bucket we are using. Suppose that we have managed to fill the barrel to the quantity of i in Best[i] steps, and it's the fewest steps possible at that moment. Then with the current bucket, we need one extra step to fill the barrel to the quantity of i+j. And of course, we will only consider the values where i+j<=N (i.e. i=0..N-j), and where Best[i]+1<Best[i+j].
![]() |
![]() |