Friday, 15 August 2014

algorithm - PHP Calculate Balanced Arrays -


OK, I'm not sure this title is effective, but the best I can come up with.

Actually this is the scenario.

I have 11 categories in each category, I have items, but one category can have 1 item, 1 in 20.

Now I want to separate 11 categories into 5 stacks or columns.

I

So the following data were given:

  category | Item ------------------------- Cat 1 | 10 cat 2 | 3 cat 3 7 cat 4 | 11 cat 5 | 5 cat 6 13 cat 7 | 19 cat 8 | 5 cat 9 3 cat 10 | 9 cat 10 | 15 total = 100 items  

So I want to spread objects equally between stacks.

There are 5 stacks so that the same thing is 20 stacks per item. But the problem is, items with over 1 stack can not overflow. So how do I calculate the data to do some output like this:

  Stack 1 | Stack 2 | Stack 3 | Stack 4 | Stack 5 ------- | ----- - | ------- | ------- | ------- Cat 10 | Cat 1 | Cat 11 | Cat 6 Cat 7 cat 4 | Cat 3 Cat 8 Cat 9 | Cat 2 | Cat 5 | 20 20 20 21 19  

It does not matter which category it is in the stack, as long as items spread evenly between the heap.

Now the results of this stack calculation will be cached, because I do not need to count too many times, if the solution is too heavy CPU, then post it.

thanks :)

This is a loose problem Many resources are you Google napsi The problem is

A simple way is to try all possible combinations. Each combination that you compute will also calculate standard deviation, use standard deviation to save the best fitting combination.


No comments:

Post a Comment