You are given a sparse 2-dimensional array of rows of columns where
each cell contains 0 or 1 string. Any two strings x and y have a
degree of affinity f(x,y) between 0 and 1. While there is no formal
rule, we have the following examples,
A3% and @! = .1
ABC and DEF12 = .5
A1B2& and 34&DE = .6
123 and 456 = .7
A123&^B and C123&^D = .8
ABCD and ABCE = .9
ABC and ABC = 1.0
and note that if A and B have a strong (say >.7) affinity and B and C
also do, then A and C usually do as well. Each column has a column
affinity defined to be the sum of the affinity of all pairs of
nonempty cells in that column. The table affinity is the sum of its
column affinities.
We are allowed to shuffle the strings left and right, moving it from
one cell to an empty cell on its left or right, thus leaving its
original cell empty. We are allowed to evaluate function f only a
limited number of times (due to time constraints.)
The problem is to shuffle the cells so as to leave the maximum table
affinity. For example, we might shuffle the cells (dash - means an
empty cell) in:
A1 - 123 - AB89
456 CD67 - - -
B1 AA999 - - -
into
A1 - 123 - AB89
- - 456 - CD67
B1 - - - AA999
if we have enough time (evaluations of function f) where A1 and B1
have a strong affinity, as do 123 and 456, and do AB89, CD67 and
AA999.
C-B