Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 int [10000] 的数组。
我需要将每个 int 与其他 int 相加,并仅显示总和 > N 的结果。
Sum,可以是任意数组元素,也可以是 5,6,7...10000 个 > N 的数组元素的总和。
我可以像 a[1] + a[2] + a[3] 一样写下(所有组合,但这太疯狂了)...但是可能还有其他解决方案吗?
我需要所有组合的结果,这给了我 >N 的总和
好的。如果它是 int[10] 的数组?
您的问题类似于子集和问题。在这里,您可以找到该算法的两种解决方案。唯一的变化是您必须跟踪总和大于 N 的数字,并且您需要针对所有可能性重复它,而不仅仅是找到真/假结果。