Editorial for IOI '15 P2 - Scales
Submitting an official solution before solving the problem yourself is a bannable offence.
This is based on the well-known problem of ordering five coins with (binary) weighings. There are
permutations and
possible sequences of seven answers, and it is indeed possible to find a strategy which always works.
In our problem, there are possible answers, and with at most
ternary weighings, theoretically we could obtain
possible answers. The gap is very small, but it turns out that it is again possible to find a strategy which uses just
weighings.
The easiest solution here is to generate a memorization function which, for each possible subset of possible permutations, tries all the possible questions, and returns the best one. It is possible to bound the branching, as follows:
- Always take care that there are at most
consistent results after
weighing, at most
consistent results after
weighings, etc.
- If, for the given subset of power
, we have already found a solution which uses
weighings, and
, then do not look further (we have already found the best possible answer).
With these optimizations, we could write a program which generates the strategy tree, in the form of a program which could be submitted for judging. With the optimizations above, it is also possible to generate it on the fly.
Comments