c - n Partitions with fixed number of elements -
i have given array of integers , should partition difference of sums minimal. size of partitions fixed (3), there n/3 partitions. should output partitions minimal sum.
i found algorithm think similar have problems understanding , adopting it: https://www.careercup.com/question?id=10244832
so understanding algorithm builds table, can check if there exists subsequence length k sums j. finds best fitting subsequence searching through table sum thats closest optimal (=arithmetical mean). array {5, 3, 1, 2} this
n = 0 1 2 3 4 5 ------------------ length=0 | 1 0 0 0 0 0 1 | 0 1 1 1 0 1 2 | 0 0 0 1 1 1 optimal sum: length=2, n=(5+3+1+2)/2=5 exists sum=5
but how adopt table n partitions? possible 2 dimensional array? , how output elements instead of sum afterwards? best guess create second array , save combinations somehow.
thanks in advance!
Comments
Post a Comment