Problem 617B

Revision en5, by ebanner, 2016-11-27 21:02:48

This is a post describing my solution for 617B - Chocolate.

For this problem, the key is viewing the act of breaking the candy bar as a sequential process with a number of decisions at each stage. Once we know how many decisions there are at each stage, we can apply the rule of product and multiply the number of decisions at each stage to arrive at the total number of possible outcomes.

The sequential process proceeds as follows:

  1. Start at the left side of the candy bar and march right
  2. Keep marching until we get between two nuts
  3. Make a break somewhere between the two nuts
  4. Go back to step 2

Step 3 is the only step where we can make multiple decisions. If there are n zeros between the two nuts, then we can give n zeros to the left nuts and 0 zeros to the right nuts, n-1 zeros to the left nut and 1 zeros to the right nut, and so on. In total, we have n decisions for this particular break.

To help visualize this process, consider the following diagram on the input sequence 10101:

We can make 2 breaks between the first and the second nut and 2 more breaks between the second and third nut for a total of 2*2 = 4 possible breaks.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English ebanner 2016-11-27 21:35:36 798 Tiny change: 'e two nuts; hence the' - (published)
en7 English ebanner 2016-11-27 21:15:47 1063 Tiny change: ' candy bar and march right\n2. Keep ' -
en6 English ebanner 2016-11-27 21:03:32 28
en5 English ebanner 2016-11-27 21:02:48 633
en4 English ebanner 2016-11-27 20:14:55 159
en3 English ebanner 2016-11-27 20:12:12 730
en2 English ebanner 2016-11-27 20:06:29 8 Tiny change: 'YD2/pub?w=960&h=720)' -
en1 English ebanner 2016-11-26 22:55:10 507 Initial revision (saved to drafts)