I guess there is a "standard" algorithm for problems of this type.. the template would look like this:
given the integer n and n numbers, find the smallest sum you can get by adding the numbers like this:
n1+n2+n1+n2+n3+n1+n2+n3+n4...
the obvious way for me was to do some math on it and get the following;
for n = 5
you get
(n-1)(N1+N2)+(n-2)N3+(n-3)N4+(n-4)N5

so... from this i just thought sorting the array would do...
but it doesn't seem to be the right way... help!!!

Recommended Answers

All 2 Replies

Your problem is the same as finding the smallest contiguous subsequence sum in the sequence

[n1, n1 + n2, n1 + n2 + n3, n1 + n2 + n3 + n4, ...].

Transform your sequence into this form and then solve the problem I described.

Come to think of it, solving the problem I described may involve doing the same transformation one more time.

Its very interesting I like your thinking I appreciate you.Really I like your attitude.How will you get this type of knowledge.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.