0%

Codeforces Round 1048 (Div. 2)——E2. Maple and Tree Beauty (Hard Version)(bitset的使用,变长bitset)

思路讲解

Codeforces Round 1048 (Div. 2)——E1. Maple and Tree Beauty (Easy Version)(背包问题)(子集枚举→能否凑出某个的和)

不难发现,用背包会TLE。

说实话,这个就真没招了,看题解吧。

其实用bitset 优化一下就能过去。

最后发现,我这样分一个if else 的反而更快

还有一种曲线救国方法。使用模板参数。

1
2
3
4
5
6
7
template <int maxn>
inline void __() {
// cin >> N >> K;
if (maxn <= N) {
__< min(maxn * 2, (int)MAXN) >();
return;
}

AC代码

https://codeforces.com/contest/2139/submission/337943651

O(N2/w)O(N^2/w) 的时间复杂度,能够过去。

心路历程(WA,TLE,MLE……)