C# algorithm - find least number of objects necessary

后端 未结 6 1103
孤街浪徒
孤街浪徒 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:16

    This is an NP-complete problem called the knapsack problem. That means, that your best method is not going to be in polynomial time. You may have to brute-force a solution.

    alt text

提交回复
热议问题