Skip to content

Commit

Permalink
Update Readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Feb 25, 2023
1 parent 0f84234 commit 1a0f5ef
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
return ret + bonus;
}
```
上面的```dfs(count, presum, i)```表示我们已经选择了i-1个groups(它们的前缀和是presum、已有的得分记做prescore),我们从剩下的groups挑选一个安排在第i个。选哪个好呢?我们不知道,必须每种可能都尝试一次,结合相应的```dfs(..., i+1)```来判断。这里需要注意的是,如果此时的presum恰好被batch整除,那么说明无论第i个元素取谁,我们都可以得到1分,所以下次递归的时候prescore可以增加1
上面的```dfs(count, presum, i)```表示我们已经选择了i-1个groups(它们的前缀和是presum,哪些被选择了记录在count里),我们从剩下的groups挑选一个安排在第i个。选哪个好呢?我们不知道,必须每种可能都尝试一次,结合相应的```dfs(..., i+1)```来判断。这里需要注意的是,如果此时的presum恰好被batch整除,那么说明无论第i个元素取谁,我们都可以得到1分。所以返回的答案就是下轮递归 里的最大值,再加本轮的1
以上的解法自然会TLE,原因是什么呢?显然是没有记忆化。我们可以发现,dfs函数中,其实只要确定了当前的count(即未被安排的groups),其他的参数presum本质上就是确定了的。所以记忆化的key其实就是count。但是count是一个数组,如何将转化为一个方便的key呢?和状态压缩相同的原因。因为count[i]最多30个,用五个bit就能表示(0~32)。batch最多是9,所以总共45位的二进制数就可以表述count数组。这就要求这个key是long long类型。
Expand Down

0 comments on commit 1a0f5ef

Please sign in to comment.