I am not even sure if this can be done in polynomial time.
Problem:
Given two arrays of real numbers,
A = (a[1], a[2], ..., a[n]), B = (b[1], b[2], ..., b[n]), (b[j] > 0, j = 1, 2, ..., n)and a number
k, find a subsetA'ofA (A' = (a[i(1)],, which contains exactly
a[i(2)], ..., a[i(k)]))kelements, such that,(sum a[i(j)])/(sum b[i(j)])is maximized, wherej = 1, 2, ..., k.
For example, if k == 3, and {a[1], a[5], a[7]} is the result, then
(a[1] + a[5] + a[7])/(b[1] + b[5] + b[7])
should be larger than any other combination. Any clue?
Assuming that the entries of
Bare positive (it sounds as though this special case might be useful to you), there is anO(n^2 log n)algorithm.Let’s first solve the problem of deciding, for a particular
t, whether there exists a solution such thatClearing the denominator, this condition is equivalent to
All we have to do is choose the
klargest values ofa[i(j)] - t*b[i(j)].Now, in order to solve the problem when
tis unknown, we use a kinetic algorithm. Think oftas being a time variable; we are interested in the evolution of a one-dimensional physical system withnparticles having initial positionsAand velocities-B. Each particle crosses each other particle at most one time, so the number of events isO(n^2). In between crossings, the optimum ofsum (a[i(j)] - t*b[i(j)])changes linearly, because the same subset ofkis optimal.