Find the minimal composition from n sets that satisfies the given condition.

53 Views Asked by At

We have N sets of triples, like

1. { (4; 0,1), (5 ; 0.3), (7; 0,6) }
2. { (7; 0.2), (8 ; 0.4), (1 ; 0.4) }
...
N. { (6; 0.3), (1; 0.2), (9 ; 0.5) }

and need to choose only one pair from each triple, so that the sum of the first members in pair will be minimal, but also we have a condition that sum of the second members in pair must be not less than a given $P$ number.

We can solve this by sorting all possible pair combinations with the sum of their first members ($3 ^ N$ combinations), and in that sorted list choose the first one which also satisfies the second condition.

Could you please help to suggest a better, non trivial solution for this problem?

1

There are 1 best solutions below

6
On

If the first element is integer, we can process lines one-by-one, maintaining for each $k$ "maximal sum of second elements if sum of first is not more then $k$".

In your example after processing the second line, we will find that we can achieve sum $0.5$ of the second elements with sum $5$ of the firsts, sum $0.7$ with $6$ and sum $1.0$ with $8$.

It is pseudopolynomial - time is proporcinal to $N \cdot \text{sum of first elements}$.

This problem is NP complete. To reduce knapsack with max weight $W$ and min cost $V$ to it, and we transform item with weight $w_i$ and cost $v_i$ to triplet $(w_i, v_i), (0, 0), (0, 0)$. Then we ask if there is family of triplets with sum of second terms been at least $V$ and sum of first at most $W$. Such triplets corresponds to solutions of knapsack problem.