Optimal Choice Algorithm

Given the many sets of people (similar to):

[p1,p2,p3] [p2,p3] [p1] [p1] 

Choose 1 from each set, trying to minimize the maximum number of times when one person is selected.

For the above sets, the maximum number of times that a given person MUST be selected is 2.

I am trying to get an algorithm for this. I do not think that this can be done using a greedy algorithm, thinking more about a dynamic software solution.

Any clues on how to do this? Or do any of you know any good sites about this material that I could take a look at?

+4
source share
1 answer

It is neither dynamic nor greedy. First, consider another problem - can this be done by selecting each person no more than once?

You have people P and S. Create a graph with vertices S + P representing sets and people. There is a line between human pi and set si iff pi - the si element. This is a two-way graph , and the version of the solution to your problem is then equivalent to checking that the maximum power match in this graph is of size S.

As described in detail on this page, this problem can be solved using the maximum flow algorithm (note: if you don’t know what I’ll talk about, then take the time to read it now, since you won’t understand the rest otherwise): first create super source, add a link to it linking it with all people with capacity 1 (which means that everyone can once), then create a super receiver and add edges connecting each set with this receiver with capacity 1 (representing that each set can use sya only once), and a suitable algorithm to run the maximum flow between a source and receiver.

Now consider a slightly different problem: can this be done by selecting each person no more than k times?

If you paid attention to the remarks in the last paragraph, you should know the answer: just change the capacity of the edges, leaving a super-source to indicate that each person can be used more than once in this case.

Therefore, now you have an algorithm for solving the problem of solution, in which people are selected no more than k . It is easy to see that if you can do this with k, you can also do it with any value greater than k, i.e. a monotonic function. Thus, you can run a binary search in the solution version of the problem by looking for the smallest possible value of k that still works.

Note. You can also get rid of the binary search by sequentially testing each value of k and increasing the residual network obtained in the last run, instead of starting from scratch. However, I decided to explain the binary search version, as it is conceptually simpler.

+5
source

Source: https://habr.com/ru/post/1437702/


All Articles