了解Kadane的算法实现和C++中的整数限制

发布于 2025-01-27 09:10:57 字数 1776 浏览 6 评论 0原文

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

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

发布评论

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

评论(1

狼亦尘 2025-02-03 09:10:57
  1. 您是否听说过 prefix sums ? (又称总计,累积总和,扫描)。 n+1是因为前缀总和还需要包括一个空子阵列。
  2. 您使用int_min最大值,因为max()函数将两个值中的较大的函数占据,因此maxsum始终增加。如果您在开始或其他数字时制作maxsum = 0,则有可能0大于任何实际总和。为了确保默认值不会覆盖实际值,您将其设置为尽可能低。
  1. Have you heard of prefix sums? (aka running totals, cumulative sums, scans). N+1 is used because prefix sums also needs to include an empty subarray.
  2. You use INT_MIN for maximum because the max() function takes the larger of the two values, so MaxSum is always increasing. If you make MaxSum = 0 at the beginning, or some other number, there is a chance that 0 is larger than any of the actual sums. To make sure that the default value does not override the actual values, you set it to as low as possible.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文