Editorial for COCI '08 Contest 2 #3 Perket


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

The number of ingredients is small enough to try every subset of them and find which of them yields the smallest absolute difference between sourness and bitterness.

The recursive function takes three arguments:

  • The index of the next ingredient for which we will decide whether to put it in the meal or not;
  • The total sourness so far;
  • The total bitterness so far.

In each recursive call, we make one decision, branching into two new recursive calls. In one branch we don't use the current ingredient, in the other we do (updating the bitterness and sourness).


Comments

There are no comments at the moment.