Algorithm that groups so that the amount is close to the target value

I am trying to find an algorithm, but googling my exact problem does not find the exact result that I need.

I am assigned a set of numbers and a target amount. I need to assign numbers to groups so that the sum of these groups is as close as possible without going over the target value.

Example Target Sum = 99
Example Set = { 70, 40, 10, 70, 98, 14, 4, 7, 29, 11, 91, 50, 30 }

The desired results will be something like this:

{ 70, 29 } 
{ 40, 50, 7} 
{ 98 } 
{ 91, 4 }
{ 70, 10, 11 } 
{ 30, 14 }

... because they all make up a number close to 99.

The goal is to have as few groups as possible. I do not need to worry about resources. It will run sparingly, and the number of values ​​will be quite low.

+4
source share
1 answer

, , , bin packing, NP-hard , .

, , First Fit First Fit, 2. , First Fit Decreasing (11/9)OPT+(6/9). PTAS (, , FPTAS), PTAS (1+epsilon)OPT+1, epsilon - .

, .

+4

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


All Articles