This is a post describing my solution for 617B - Chocolate.
For this problem, the key is recognizing that we can think of breaking the candy bar up into parts 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 process proceeds as follows. We proceed from left to right. We march along the candy bar until we get between two nuts. Between each pair of nuts, if there are some zeros, we have the option of including the zeros with either the left nut of the right nut. The number of choices we have is the number of zeros, plus one. We continue this for each pair of nuts separated by either none or some zeros.
To help visualize this process, consider the following diagram on the input sequence 10101
:
Here is some text afterward.