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

7.6 节 p54 “注意” #88

Closed
tracyqwerty opened this issue Feb 15, 2024 · 2 comments
Closed

7.6 节 p54 “注意” #88

tracyqwerty opened this issue Feb 15, 2024 · 2 comments

Comments

@tracyqwerty
Copy link

如果您实在不想仔细思考,这里有个简单的口诀:0-1 背包对物品的迭代放在外层,里层的体积或价值逆向遍历; 完全背包对物品的迭代放在里层,外层的体积或价值正向遍历。

此处有误。0-1 背包和完全背包对物品的迭代都放在外层。

@changgyhub
Copy link
Owner

感谢关注!

前文有提到

压缩空间时到底需要正向还是逆向遍历呢?物品和体积哪个放在外层,哪个放在内层呢?这取决于状态转移方程的依赖关系。在思考空间压缩前,不妨将状态转移矩阵画出来,方便思考如何进行空间压缩。

另外对于一般的完全背包问题,放在里层外层都是可以的,只要状态转移支持即可,这里仅为一个懒人口诀 :) 下面抛硬币那道题便是内层迭代硬币。

@tracyqwerty
Copy link
Author

感谢回复!

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

2 participants