C# algorithm - find least number of objects necessary

后端 未结 6 1051
孤街浪徒
孤街浪徒 2021-01-14 03:19

Let\'s say I have the following code.

var numberToGetTo = 60; 
var list = new[] {10, 20, 30, 40, 50};

I want to be able to return 50 &

6条回答
  •  花落未央
    2021-01-14 04:08

    This sounds similar to the Subset sum problem, which can be solved in a reasonable amount of time for smallish sets using dynamic programming. It's not an easy or common problem, so you won't find a helpful Linq extension method for it :)

提交回复
热议问题