Skip to content
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

python/40_dynamic_programming/01_bag.py 中bag_with_max_value函数有误 #473

Open
Bernadette321 opened this issue May 14, 2020 · 0 comments

Comments

@Bernadette321
Copy link

Bernadette321 commented May 14, 2020

使用专栏中的例子weight: 2,2,4,6,3 value = 3,4,8,9,6

if __name__ == '__main__':
    # [(weight, value), ...]
    items_info = [(2, 3), (2, 4), (4, 8), (6, 9), (3, 6)]
    capacity = 9
    print(bag_with_max_value(items_info, capacity))

的结果不是18而是17
检查发现,比如:
image
刚设置了值为4, 而在下一轮的"for cur_weight in range(capacity+1)中又被设置为了3
最后的结果如下,与专栏老师讲的也不相同
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant