Algorithm to find the best combination of items under certain constraints

前端 未结 7 1654
长情又很酷
长情又很酷 2021-01-06 14:22

I\'ll try to explain the problem in the math language.
Assume I have a set of items X = {x_1, x_2, ..., x_n}. Each item of X belongs to one of

7条回答
  •  青春惊慌失措
    2021-01-06 14:40

    If we put aside the condition to take one x from each S_i, this problem is equivalent to Maximum Weight Independent Set in an interval graph (that is, finding a maximum-weight set of pairwise not connected vertices in a graph where vertices represent intervals, and vertices are connected if the corresponding intervals overlap). This problem can be solved in polynomial time. The version here also has a color for each vertex, and the chosen vertices need to have all different colors. I am not sure how to solve this in polynomial time, but you can exploit the fact that there are not too many colors: make a dynamic programming table T[C, x], where C is a set of colors and x is the position of an endpoint of an interval. T[C, x] should contain the maximum weight you can get from |C| intervals with the colors in C that are to the left of x. You can then fill in the table from left to right. This should be feasible since there are only 2^5=32 color sets.

提交回复
热议问题