Grouping an ordered dataset into a minimum number of clusters

I have an ordered list of weighted items, the weight of each is less than or equal to N. I need to convert it to a list of clusters. Each cluster should cover several consecutive elements, and the total cluster weight should be less than or equal to N.

Is there an algorithm that does this, minimizing the total number of clusters and keeping their weights as large as possible?

eg. ([a], 5), (b, 1), (c, 2), (d, 5)], N = 3), ([d], 5)]

+3
source share
2 answers

, "" , Knuth (http://en.wikipedia.org/wiki/Word_wrap), . badness ( ) ( ).

+2

.

, , . , .

, : [(a, 1), (b, 1), (c, 1), (d, 1), (e, 1)], N = 2

- [([a], 1), ([b], 1), ([c], 1), ([d], 1), ([e], 1)]

- [([a, b], 2), ([c, d], 2), ([e], 1)]

, ( ) ? , .

, 2k + 1 N/2. , k + 1 (k 2 1 1) N/2 . 2k + 1 1 , .

: , "" . ?

+1

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


All Articles