开发者

C algorithm for Partition issues

开发者 https://www.devze.com 2023-02-18 16:35 出处:网络
Given a set of integers S: How can the set be divided into k parts such that the sum of each part is minimal?

Given a set of integers S:

How can the set be divided into k parts such that the sum of each part is minimal? Please give also a C implementa开发者_运维问答tion.

Example:

S = {1, 2, 3, 4, 5, 6} and k = 3

The partition

 S1 = {1, 6}
 S2 = {2, 5}
 S3 = {3, 4}

has the property that the sum of each partition is minimal.


This page describes the problem fairly well and even provides pseudocode for an algorithm:

http://www8.cs.umu.se/kurser/TDBAfl/VT06/algorithms/BOOK/BOOK2/NODE45.HTM


Determine min, max in the given list and form a pair. Repeat until the list is exhausted.

Intuitively it seems it will ensure the desired result, but not sure though!

0

精彩评论

暂无评论...
验证码 换一张
取 消