在给定的数字序列中找到k数的组合,以满足条件

发布于 2025-01-29 14:59:02 字数 486 浏览 1 评论 0原文

我有这样的问题:

给定一个带有n 的数字列表(10< = n< = 60)数字x1,x2,...,xn 这样1< = XJ< = 10。输入数字k (1< = k< = 8),输入 数字m (0< = m< = 9)。在给定的k数字中找到一个组合 数字列表,以使发现Modulo 10的k数量总和10 等于m。例如:对于序列n = {1,3,5,6,3,7,2,9,10,3,4,6} 在k = 3和m = 5的情况下,令人满意的组合之一是{5,6.4} - > (5 + 6 + 4)%10 = 5

我想找到解决问题的最佳解决方案,但是除了使用递归来蛮力外,我还没有找到其他方法。有比蛮力更好的方法吗? 谢谢您的阅读!

I have a problem like this:

Given a list of numbers with n (10 <= n <= 60) numbers x1, x2,..., xn
such that 1 <= xj <= 10. Enter the number k (1 <= k <= 8), enter the
number m (0 <= m <= 9). Find a combination of k numbers in the given
list of numbers such that the sum of the k numbers found modulo 10
equals m. For example: for the sequence N = {1,3,5,6,3,7,2,9,10,3,4,6}
with k = 3 and m = 5, then one of the satisfying combinations is {5,6.4} -> (5 + 6 + 4) % 10 = 5.

I want to find the optimal solution to the problem but i haven't found a way other than using recursion to brute-force. Is there a better way than brute-force?
Thank you for your reading!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文