Editorial for IOI '04 P5 - Farmer
Submitting an official solution before solving the problem yourself is a bannable offence.
Let be a field or a strip. Denote by the number of cypresses in a field or a strip. If we denote by the number of olive trees in a , we have: if is a field or if is a strip.
Consider now the following KNAPSACK problem: , such that and , where are the numbers of fields and strips respectively.
An optimum solution , , of this problem consists of a subset of such that the total number of their cypresses is at most and the total number of the included olive trees is maximized. However in general . If this is the case, then there is some such that and , for otherwise the optimum solution can be improved by the inclusion of , a contradiction. Therefore, adding a chain of cypresses of and its olive trees to the optimum solution of the knapsack problem above, yields an optimum solution. The KNAPSACK problem can be solved optimally in time by a Dynamic Programming algorithm.
Comments