Editorial for APIO '07 P3 - Zoo
Submitting an official solution before solving the problem yourself is a bannable offence.
This is a special case of Max-SAT, where each clause can only contain variables which are close together (in a circular order). Specifically:
- Each animal is a boolean variable in Max-SAT. We have variables in a circular order.
- Each child is a clause in Max-SAT. If a child can see consecutive enclosures, this means that each clause may only contain variables for some (where , and so on). For this problem, we are given .
A model solution uses dynamic programming.
Linear case
Consider a simpler problem when the enclosures are placed in a linear order (i.e., does not wrap back around to ). For each , let be the set of all children whose visible enclosures lie in the range . We iterate through , and at each stage we solve problems of the following form:
Consider the set of children , and consider all ways in which the final enclosures may be filled or empty. For each filled/empty combination for enclosures , what is the maximum number of children in who can be made happy?
We solve the problems at stage as follows. We assume we have already computed the maximum number of happy children in for all filled/empty combinations for enclosures . To calculate the new answers for stage and a particular filled/empty combination for enclosures :
- We count how many "new" children in are made happy. We can calculate this directly from our choice of filled/empty values for , because every "new" child is looking at precisely these enclosures.
- Assuming the "old" enclosure is filled, we can look up our solutions from stage to find out how many children in can be made happy with our selected filled/empty values for . Likewise, we can look up how many children in can be made happy when the old enclosure is empty. The larger of these two numbers tells us how many "old" children in we can keep happy overall.
- The number of happy "new" children from step 1 can be added to the number of happy "old" children from step 2, giving the solution to our current problem.
The total number of problems to solve is , and the overall running time for the algorithm is . The space required is only , since each stage only requires the solutions from the previous stage .
Circular case
In the circular case, we need to permanently remember the states of the first enclosures (in addition to the "most recent" enclosures ). This allows us to correctly deal with the final children who can see back around past to again. The remainder of the algorithm remains more or less the same.
We therefore have problems to solve at each stage, giving running time and storage space .
Comments