尝试所有排列

发布于 2024-09-01 11:18:08 字数 264 浏览 1 评论 0原文

对于我的程序,我试图帮助用户,并减少他或她的工作量。

有四个输入数字。它们也可以应用数量不确定的数字。

例如,它们的四个输入数字可能是 {4,7,3,2},它们可以应用到的数字是 {4,9,23}

结果应该是:4(输入)被应用到 4,留下集合看起来像:{0,7,3,2},然后 7,2(输入)应用于 9,留下集合看起来像:{0,0,3,0} 和 {0,0,23} 并且因为3 或包括 3 在内的任何其他排列与 23 不匹配,仍保留 3。

我该怎么做?

For my program, I am trying to assist the user, and reduce his or her work load.

There are four input numbers. There is also an indeterminate amount of numbers they can be applied too.

For example, they four input numbers could be {4,7,3,2} and the numbers they can be applied to are {4,9,23}

The result should be: 4 (input) was applied to 4, leaving the sets looking like: {0,7,3,2} and then 7,2 (input) are applied to 9 leaving the sets looking like: {0,0,3,0} and {0,0,23} and because 3 or any other permutation including 3 does not match 23, 3 remains.

How would I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空城旧梦 2024-09-08 11:18:08

您是说您想从输入集中查找与另一个集中的值相加的项目吗?
如果是这样,那么我相信这是子集和问题的一个实例,这是一个特殊的问题背包问题的情况。

子集和是 NP 完全的。如果集合很大,您所能做的最好的就是近似解决方案。

Are you saying that you want to find the items from the input set that sum to a value in the other set?
If so, then I believe this is an instance of the Subset Sum Problem, which is a special case of the Knapsack Problem.

Subset Sum is NP-Complete. If the sets are large, the best you will be able to do is an approximate solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文