C#算法

编程入门 行业动态 更新时间:2024-10-12 05:50:43
本文介绍了C#算法 - 寻找最少数量的必要对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

让我们说我有以下的code。

Let's say I have the following code.

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

我希望能够回到50安培; 10从列表中= 60。

I want to be able to return 50 & 10 from list to = 60.

如果该numberToGetTo 100我想回到50,50。

If the numberToGetTo was 100 I would want to return 50, 50.

如果该numberToGetTo是85我想回到50,40。

If the numberToGetTo was 85 I would want to return 50, 40.

我想从必要去了numberToGetTo列表返回最少的数字,而住最接近(等于或greather),而不是它。

I want to return the least amount of numbers from the list necessary to get to the "numberToGetTo", while staying closest (equal or greather) than to it.

在做这样的事情的LINQ可能吗?

Is doing something like this with Linq possible?

推荐答案

这是一个NP完全问题称为背包问题。这意味着,你最好的方法是不是要在多项式时间。您可能需要暴力破解的解决方案。

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.

更多推荐

C#算法

本文发布于:2023-11-30 00:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!