0%

思路讲解

image

注意到,根据题设条件,树必须为严格的“Y”||”1”。

AC代码

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

注意,写两种dfs记得要清空vis数组。

思路讲解

首先,遇到数论问题不要怕,我们人类其实对许多数论问题其实都束手无策,就靠计算机枚举。

那么,通过素因数分解,不难发现,我们可以把问题转化为这个。

💡 Note: 给你一个序列,比如说1,2,2,3,5,你要将这个序列删空,你一次可以选择任意多的数,只要这些数的乘积小于K。要求你找到一个方式,使用最少删除次数,告诉我这个次数。

那么其实经过素因数分解得出的序列是不会有 1 的。

image

把xrem除掉,再乘上yrem,就相等了。


记忆化搜索的时间复杂度那基本上等于 状态数×入口数量状态数\times入口数量,这里的状态数量其实就是因数的数量,入口数量也是因数数量,所以最坏情况下时间复杂度为 O(n23)O(n^{\frac{2}{3}})

image

这个super composite number 就是因数数量特别多的数,比比他小的所有数的因数都多,那么这样的数大概因数数量也就是 n3\sqrt[3]{n}

highly composite number is a positive integer that has more divisors than all smaller positive integers. If d(n) denotes the number of divisors of a positive integer n, then a positive integer N is highly composite if d(N) > d(n) for all n < N. For example, 6 is highly composite because d(6)=4, and for n=1,2,3,4,5, you get d(n)=1,2,2,3,2, respectively, which are all less than 4.

1
2
3
4
5
6
7
8
9
10
11
12
ll dfs(ll val){
if(dp[val]!=INF) return dp[val]+1;
if(val==1) return 1;
FOR(i,0,SZ(facs)-1){
ll fac=facs[i];
if(fac==1) continue;
if(fac>K) break;
if(val%fac==0) dp[val]=min(dp[val],dfs(val/fac));
}
return dp[val]+1;
}

那么问题的关键就在于减少入口,注意到只有因数是合法的。

AC代码

https://codeforces.com/contest/2114/submission/323597405

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

思路讲解

是比较简单的树上dp问题,记录一下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void dfs(ll node,ll x0,ll x1,ll cnt){
// x0表示cnt%2==0时加
if(vis[node]) return;
vis[node]=true;
ans[node]= cnt%2==0?A[node]+x1:A[node]+x0;
if(cnt%2==0){
x0-=A[node];
x1+=A[node];
}
if(cnt%2==1){
x0+=A[node];
x1-=A[node];
}
FOR(i,0,SZ(g[node])-1){
ll lnode=g[node][i];
if(vis[lnode]) continue;
dfs(lnode,max(0ll,x0),max(0ll,x1),cnt+1);
}
}

AC代码

https://codeforces.com/contest/2114/submission/323228554

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

思路讲解

感觉每次选择都可能有后效性怎么办?

1
2
3
// 碰到b,a   c,a operate 在最近的位置
// a,b a,c not operate
// b,c c,b operate or not?

仔细一想那,这道题目也没有那么复杂其实,其实只有b,c是需要考虑是否操作的。

只考虑那么一种情况的话,其实就看后面有没有c,a,而且b的前面c的数量啦。

https://www.cnblogs.com/fwdzh/p/18909502

这个题解告诉我们,我们是不可能在线处理的,这个难度是比较大的,但是我前面一直在想这个(QAQ)。

AC代码

https://codeforces.com/contest/2111/submission/322930903

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

那么我们发现,匹配应该是这样匹配,而不是用最大的匹配最小的。

1
2
3
4
5
6
7
if(*g[idx2].begin()<*g[idx3].rbegin()){
// g[idx2].pop_front();
auto it=g[idx3].lower_bound(*g[idx2].begin());
g[idx2].erase(g[idx2].begin());
g[idx3].erase(it);
s[i]='a';
}

思路讲解

这道D题确实不算太难,我赛时应该也是可以写出来的。

采用类似于下图的构造方式即可

image

AC代码

https://codeforces.com/contest/2111/submission/322856069

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