In first place, I suspected this could be a NP-complete problem but later I suspected I was mistaken because some "backdoor" algorithm might exist. However, this article on the problem states that it is indeed a NP-complete one. But only when I learned from the same article that there are different Knapsack and Knapsack-like problems, only then I paid closer attention to the formulation of the present Question. Silly me!

Well, this is neither basic nor generalized Knapsack problem, so let's consider this is a Knapsack-like problem, rather simplified. The formulation is contradictory: the words "I need some help solving an algorithm in C#" hint that general algorithm is required, but is this case, why giving the following constraints:

`W = 15, N = 17, S = [1, 2, 4, 9]`

? With this figures, formally speaking, algorithm is not required, proven solution would be the answer.As my mood of relaxing after the Christmas Eve party does not inspire much enthusiasm for working at the general algorithm, let' first think about the formal solution with constraints.

Ok, we can immediately see that

**there is no solution**.

__The proof__: as minimum S=1, minimum sum of N weights is equal to N*1 = N = 17, which is more than W = 15. Now, follow the most delicate and hard-to-understand inference: if minimum sum of N weights is less then W, any other combination of N weights is more than W => no combination of N weights is equal to W => :thumbsdown: ---- ;)

Aha, now we can see that the inquirer is locked in the corner. I do understand that shaden2009 could have done a simple mistake; and the figures could be different. Who knows? Slip of a hand. May be W and N should be swapped; then the problem is solvable... --

**too late!**The proof is presented, and shaden2009 assumed sole responsibility for the formulation of the problem.

In this way, shaden2009, being a undoubtedly, honest person (we all are supposed to be honest aren't we?) has nothing to do but accept my answer now.

If there is more accurate formulation of the problem which would make it more sensible, we would certainly enjoy considering it (shall we?), but that should be another question. The present answer should be accepted; and the present question closed.

Thank you for attention!

Take it easy! ;)

Best wishes in New Year, everyone!

modified: The OP's original question was a rude and demanding one-liner, thus my comment.

Just plainly stating that you want a prefabricated solution from us without any sign of engagement from you, there isn't much hope for you that anybody will help at all.

If you need help re-formulating the question you can aslo ask for that, and more likely than not somebody will do just that.

No wonder as there was not much to go on anyhow, Cheers!

Happy Xmas, solstice or whatever you're celebrating this time of the year :)

R. Giskard Reventlov24-Dec-10 10:41amSAKryukov:When you click on the link "Revision" below the question you can review older versions of the question including the original post. If you look at the version of the question OP had posted you'd probably understand Smithers-Jones first comment. :)One example, just for fun. Recently, there was a discussion of one other inquirer behavior, pretty much like this one (but, to me, more of the inquirer's fault). In next question, the inquirer requested: "Please don't post irrelevant comments" -- as if not paying enough attention for good answers, asking same question again several times and failure to work and learn would be less of distraction...

I like people who work hard to learn something good too much. Lazy and ignorant people effectively steal from them even more than from us answering questions.

Best wished in New Year to everyone!