Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

修改 0494.目标和 中Python二维DP版本状态转移判断 #2927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FuTau wants to merge 1 commit into youngyangyang04:master
base: master
Choose a base branch
Loading
from FuTau:master

Conversation

Copy link

@FuTau FuTau commented Apr 2, 2025

判断条件使用了nums[i-1]而不是当前处理的元素nums[i]。这导致在处理第i个元素时错误地检查了前一个元素的值,从而导致状态转移错误。

正确的条件应为j >= nums[i],以确保当前元素nums[i]可以被选中。

同时建议可以去除初始化时对0元素的操作,在双重循环中当我们碰到0的时候,dp[i][j]会被加2次,这就与2^(0的个数)相对应了。

判断条件使用了nums[i-1]而不是当前处理的元素nums[i]。这导致在处理第i个元素时错误地检查了前一个元素的值,从而导致状态转移错误。
正确的条件应为j >= nums[i],以确保当前元素nums[i]可以被选中。
同时建议可以去除初始化时对0元素的操作,在双重循环中当我们碰到0的时候,dp[i][j]会被加2次,这就与2^(0的个数)相对应了。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /