Question about the for loop condition to efficientlly iterate all subset
qh-huang opened this issue · comments
qiao commented
Hi wisdompeak,
In the README.md
, you mentioned a template
for (int state=1; state<(1<<n); state++)
for (int subset=state; subset>0; subset=(subset-1)&state)
{
dp[state] = DoSomething(dp[subset]);
}
The inner for
loop condition implies when (subset-1&state) == 0
, there's no need to search the next subset
with the same state
.
However, I'm confuse about the reason, would you please explain it or give me some hint?
Thanks.
yangizone commented
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
wisdompeak commented
if you write something like for (int subset=state; subset>=0; subset=(subset-1)&state)
, the loop would never end.