Editorial for Baltic OI '10 P4 - Matching Bins
Submitting an official solution before solving the problem yourself is a bannable offence.
Let be the input sequence of bins and
for
. The
leftmost bins can be put into the next
bins in some order if and only if
and there exists a permutation
of the numbers
, such that
The solution to the problem is the largest satisfying condition (1). Assume that
is a solution and
is a permutation satisfying condition (1). Let
and
and
It is obvious that . Assume that
and
. Then
Therefore we can modify the permutation such that
and
, and the modified
also satisfies condition (1). Let
be the number of bins of size
in the first
bins, and
be the number of bins of size
in the next
bins, that is
Define and
and
Now we can state that the leftmost bins can be put into the next
bins in some order if and only if condition (2) holds.
Values of and
can be computed in
running time and then checking for the condition (2) takes
time. Therefore for a given value of
we can check whether
is a solution in
time. Moreover, if we already computed the values of
and
for a given
then for
we have to modify
,
,
and
only. As a consequence, we obtain an
worst case running time algorithm. The required memory is
.
We can speed up a bit by recomputing only those that might be changed by decreasing the value of
.
Comments
What does "ii" and "jj" mean? it is just literally i * i and j * j? Sorry I'm not used to read solutions. Thanks