|
|
English versionFirstly, consider a classical dp to calculate $dp_{u,k}$ as the number of delete $k$ vertices in subtree $u$ without considering deleting vertex $n-i+1$ everyday. This is trivial. Then, due to the existence of an “automatic deletion” process, we cannot view the selected points within the subtree of $u$ as operations with only relative order, because they may be illegal. However, we consider the final operation sequence, putting the vertex chosen on the $i$ th day in the position $n-i+1$. That is, if we firstly choose $4$, then $3$, then $1$, it will be $0431$. Then, one vertex $u$ must be put in position $u$ or later. Then, we find that for the subtree of vertex $u$ with DFS order interval $[l,r]$, all vertex can't be put in position before $l$, and always legal to put in position after $r$ if parent-child relations are satisfied. So we consider a dp $f_{u,i,j,k}$ which represents that the subtree of $u$ leaves position $i$ for ancestors (which means nothing can be placed at position $i$ or before, and if $i=0$, then nothing is left for ancestors), there are $j$ empty spaces (not including the one left for ancestors), and $k$ vertices need to be put into positions after the subtree of $u$. In the $i=0$ case,we merge subtrees,and the subtree with smaller DFS order can put some backward operations into the space of the subtree with bigger DFS order. Specifically, consider the sons of $u$ enumerated in reverse order of DFS, and the son is $v$.Then enumerate $w$ as how many backward operations from $v$ will fill in space of $u$. The transition is $f_{u,0,j+j1-w,k+k1-w} \leftarrow f_{u,0,j+j1-w,k+k1-w}+f_{u,0,j,k}\times f_{v,0,j1,k1}\times {j \choose w}\times{k+k1-w \choose k}$. For $f_{v,i,j,k}(i\neq 0)$, it won't interfere the transition with its following siblings. And for $f_{u,i,j,k}$, just consider where to put $u$. The answer for $i$ operations is $f_{1,i,i-2,0}$. 中文版本对于树上选一个点删去一个子树方案数这个经典问题,一个常见的 dp 是记 $dp_{u,k}$ 为 $u$ 子树选 $k$ 个点方案数,转移时兄弟间用组合数将其合并,然后祖先要选就必须选在它们前面,这一部分 $O(n^2)$。 回到本题,由于存在“自动删点”的过程因此我们不能将 $u$ 子树内选的点看成只有相对顺序的操作,因为其可能不合法。但我们考虑最终的操作序列,没有的位置留空:比如样例 $1$ 中第一次选 $4$,第二次选 $3$,第三次选 $1$,那么操作序列即为 $0 4 3 1$。也就是第 $i$ 次选的点放在 $n-i+1$ 的位置上。这样,我们发现一个点 $u$ 只能填在 $u$ 及以后的位置,那么对于一个点 $u$ 的子树,其 dfs 序区间为 $[l,r]$,那么 $u$ 子树的点填到 $r$ 以后的位置一定合法,而 $u$ 留的空其前面的兄弟和祖先填进去只要没有父子关系干扰一定合法,于是我们考虑 dp。 考虑一个 dp $f_{u,i,j,k}$ 表示 $u$ 子树 $i$ 这个位置留给祖先(也就是说 $i$ 及以前不能放东西,如果 $i=0$ 就不留),有 $j$ 个空(不包含给祖先留的),有 $k$ 个点要填到 $u$ 子树以后的位置。先考虑 $i=0$ 情况。那么合并两个子树的时候就是 dfs 序更小的子树可以选一些向后的操作填到 dfs 序更大子树的空里面。然后两个子树的空合并,向后操作合并。 具体来说,考虑 $u$ 的儿子按 dfs 序倒序枚举,对于一个儿子 $v$,那么合并 $f_{u,0,j,k}$ 和 $f_{v,0,j1,k1}$ 的时候先枚举一个 $w$ 代表选多少个 $v$ 中的向后操作填到 $u$ 的 $v$ 之后的子树,转移即为 $f_{u,0,j+j1-w,k+k1-w}\leftarrow f_{u,0,j+j1-w,k+k1-w}+f_{u,0,j,k}\times f_{v,0,j1,k1}\times {j \choose w}\times{k+k1-w \choose k}$。 再考虑 $f_{v,i,j1,k1}$ ,发现它需要给祖先留空并不影响其和后面兄弟的转移,因此转移同上,只是 $v$ 留的空 $u$ 同样需要留,所以转移到 $f_{u,i,j+j1-w,k+k1-w}$。注意这里需要预处理转移系数(因为 $i$ 取任何值转移系数相同)才能达到 $O(n^5)$。 然后考虑 $f_{u,i,j,k}$ 的转移,即 $v$ 后面的子树已经留了空。那么 $v$ 子树现在不能放任何东西,但是可以用一些向后的操作填 $i$ 后面的空,这里用 $dp_{v,k}$ 去转移即可。 子树转移完后,接下来是 $u$ 自身的操作。$u$ 可以有几种选择:
最后求答案的时候,对于要求 $k$ 次操作,相当于给 $1$ 在 $n-k+1$ 的位置留了空,同时恰好只有 $n-k$ 个空(那么后面就没有空,就是合法的操作序列),输出即可。
题目4286 [THUPC 2025 Final] I’m Here
AAAAAAAAAAAAA
评论
2026-01-29 18:40:31
|
|
|
English versionFirstly, consider a classical dp to calculate $dp_{u,k}$ as the number of delete $k$ vertices in subtree $u$ without considering deleting vertex $n-i+1$ everyday. This is trivial. Then, due to the existence of an “automatic deletion” process, we cannot view the selected points within the subtree of $u$ as operations with only relative order, because they may be illegal. However, we consider the final operation sequence, putting the vertex chosen on the $i$ th day in the position $n-i+1$. That is, if we firstly choose $4$, then $3$, then $1$, it will be $0431$. Then, one vertex $u$ must be put in position $u$ or later. Then, we find that for the subtree of vertex $u$ with DFS order interval $[l,r]$, all vertex can't be put in position before $l$, and always legal to put in position after $r$ if parent-child relations are satisfied. So we consider a dp $f_{u,i,j,k}$ which represents that the subtree of $u$ leaves position $i$ for ancestors (which means nothing can be placed at position $i$ or before, and if $i=0$, then nothing is left for ancestors), there are $j$ empty spaces (not including the one left for ancestors), and $k$ vertices need to be put into positions after the subtree of $u$. In the $i=0$ case,we merge subtrees,and the subtree with smaller DFS order can put some backward operations into the space of the subtree with bigger DFS order. Specifically, consider the sons of $u$ enumerated in reverse order of DFS, and the son is $v$.Then enumerate $w$ as how many backward operations from $v$ will fill in space of $u$. The transition is $f_{u,0,j+j1-w,k+k1-w} \leftarrow f_{u,0,j+j1-w,k+k1-w}+f_{u,0,j,k}\times f_{v,0,j1,k1}\times {j \choose w}\times{k+k1-w \choose k}$. For $f_{v,i,j,k}(i\neq 0)$, it won't interfere the transition with its following siblings. And for $f_{u,i,j,k}$, just consider where to put $u$. The answer for $i$ operations is $f_{1,i,i-2,0}$. 中文版本对于树上选一个点删去一个子树方案数这个经典问题,一个常见的 dp 是记 $dp_{u,k}$ 为 $u$ 子树选 $k$ 个点方案数,转移时兄弟间用组合数将其合并,然后祖先要选就必须选在它们前面,这一部分 $O(n^2)$。 回到本题,由于存在“自动删点”的过程因此我们不能将 $u$ 子树内选的点看成只有相对顺序的操作,因为其可能不合法。但我们考虑最终的操作序列,没有的位置留空:比如样例 $1$ 中第一次选 $4$,第二次选 $3$,第三次选 $1$,那么操作序列即为 $0 4 3 1$。也就是第 $i$ 次选的点放在 $n-i+1$ 的位置上。这样,我们发现一个点 $u$ 只能填在 $u$ 及以后的位置,那么对于一个点 $u$ 的子树,其 dfs 序区间为 $[l,r]$,那么 $u$ 子树的点填到 $r$ 以后的位置一定合法,而 $u$ 留的空其前面的兄弟和祖先填进去只要没有父子关系干扰一定合法,于是我们考虑 dp。 考虑一个 dp $f_{u,i,j,k}$ 表示 $u$ 子树 $i$ 这个位置留给祖先(也就是说 $i$ 及以前不能放东西,如果 $i=0$ 就不留),有 $j$ 个空(不包含给祖先留的),有 $k$ 个点要填到 $u$ 子树以后的位置。先考虑 $i=0$ 情况。那么合并两个子树的时候就是 dfs 序更小的子树可以选一些向后的操作填到 dfs 序更大子树的空里面。然后两个子树的空合并,向后操作合并。 具体来说,考虑 $u$ 的儿子按 dfs 序倒序枚举,对于一个儿子 $v$,那么合并 $f_{u,0,j,k}$ 和 $f_{v,0,j1,k1}$ 的时候先枚举一个 $w$ 代表选多少个 $v$ 中的向后操作填到 $u$ 的 $v$ 之后的子树,转移即为 $f_{u,0,j+j1-w,k+k1-w}\leftarrow f_{u,0,j+j1-w,k+k1-w}+f_{u,0,j,k}\times f_{v,0,j1,k1}\times {j \choose w}\times{k+k1-w \choose k}$。 再考虑 $f_{v,i,j1,k1}$ ,发现它需要给祖先留空并不影响其和后面兄弟的转移,因此转移同上,只是 $v$ 留的空 $u$ 同样需要留,所以转移到 $f_{u,i,j+j1-w,k+k1-w}$。注意这里需要预处理转移系数(因为 $i$ 取任何值转移系数相同)才能达到 $O(n^5)$。 然后考虑 $f_{u,i,j,k}$ 的转移,即 $v$ 后面的子树已经留了空。那么 $v$ 子树现在不能放任何东西,但是可以用一些向后的操作填 $i$ 后面的空,这里用 $dp_{v,k}$ 去转移即可。 子树转移完后,接下来是 $u$ 自身的操作。$u$ 可以有几种选择:
最后求答案的时候,对于要求 $k$ 次操作,相当于给 $1$ 在 $n-k+1$ 的位置留了空,同时恰好只有 $n-k$ 个空(那么后面就没有空,就是合法的操作序列),输出即可。
题目4286 [THUPC 2025 Final] I’m Here
AAAAAAAAAAAAA
评论
2026-01-29 18:39:27
|
|
|
简要题意对于三个长度为 $n$ 的 现在我们有三个长度为 $n$ 的随机 $n \le 3 \times 10^5$ 解法引理:设 $\text{maj}(a,b,c)$ 为 $a,b,c$ 中的众数;对于三个长度为 $n$ 的 01 字符串 $s_1,s_2,s_3$,设 $\text{maj}(s_1,s_2,s_3)$ 为长度为 $n$ 的字符串 $t$,其中 $t_i = \text{maj}(s_{1,i},s_{2,i},s_{3,i})$,则 $f(s_1,s_2,s_3) = |\{s_1,s_2,s_3,\text{maj}(s_1,s_2,s_3)\}|$。 我们首先说明以上四个字符串均满足题设条件。$s_1,s_2,s_3$ 满足条件是显然的。 对于 $t=\text{maj}(s_1,s_2,s_3)$,对于任意 $1 \le i < j \le n$,存在下标 $1 \le a < b \le 3$ 满足 $s_{a,i} = s_{b,i} = t_i$,又存在 $1 \le c < d \le 3$ 满足 $s_{c,j} = s_{d,j} = t_j$。根据抽屉原理 $\{a,b,c,d\}$ 中有两个数相等,对应的下标即是满足题设条件的 $k$。 接下来我们说明不存在其它字符串满足条件。当满足条件的字符串 $t$ 不等于 $\text{maj}(s_1,s_2,s_3)$ 时,设 $t_i \ne \text{maj}(s_1,s_2,s_3)_i$,则 $t_i$ 只在 $s_{1,i},s_{2,i},s_{3,i}$ 中出现恰好一次(不能不出现,否则不可能满足题设条件),不妨假设其为 $s_{1,i}$。此时取任意 $j \ne i$,根据题设条件必然有 $t_j = s_{1,j}$(因为 $k$ 必须取 $1$),因此 $t = s_1$。 进一步地,可以分类讨论得到 $|\{s_1,s_2,s_3,\text{maj}(s_1,s_2,s_3)\}| = 4 - \sum_{i=1}^3 [\text{maj}(s_1,s_2,s_3) = s_i]$:
由于期望的线性性,只需要计算 $\Pr[\text{maj}(s_1,s_2,s_3) = s_i]$ 即可。由于每一位的随机事件是独立的,所以直接把每一位相等的概率乘起来就行了。 复杂度 $O(n)$。
题目4284 [THUPC 2025 Final] 好串
AAAAAAAAAAAAAAAAAAAAAA
评论
2026-01-29 18:38:58
|
|
|
题外话
Description
$k=0$
正解
题目4283 [THUPC 2025 Final] 石墨烯
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
评论
2026-01-29 18:38:16
|
|
|
English versionEach operation transform three adjacent characters into one. If the string starts with If the string ends with If an operation transformed a string ending with Consider the case where the strings contains All cases of
However, Since Another case is that the string ends with In the remaining case, there are even 0's between some pair of adjacent 1's, but the number of characters before the first 1 is odd, there must be only one pair. Suppose the string is 1-indexed. It is because the indices of such pair of 1's must be [odd, even]; while the indices in the previous case must be [even, odd]. Thus, if there are two such pairs of this case [odd, even], in the parity sequence [odd, even, ..., odd, even] there must be an [even, odd] as a substring. Therefore, any other pair of adjacent 1's must have odd 0's in between, i.e., $0(00)^*\color{blue}(10(00)^*)^*\color{red}1\color{black}(00)^*\color{red}1\color{blue}((00)^*01)^*\color{black}(00)^+$ in regular expression. Any operation remains the string in this case, except that the string is $0(00)^*\color{blue}(10(00)^*)^*\color{red}1\color{red}1\color{black}(00)^+$ and the operation is $\color{red}1\color{black}?\color{red}1\color{black}:0$ makes 1. Since it must ends with `00`, it becomes a string ending with `0` and every pair of adjacent 1's has odd 0's in between, which is a case mentioned before that has no solution. In conclusion, it has a solution if and only of at least one of the two following conditions is met:
中文版本英文题解里描述了做本题的一种思路,以及证明。 如果要直接写做法的话,是下面这样: 假设字符串下标从 $1$ 开始编号。 首先判断是否存在 $i,j$ 使得 $i$ 是奇数,$j$ 是偶数,$s_i$ 和 $s_j$ 都是
此外,还有一种比较特别的解法: 可以发现构造的过程中需要用到不超过两层括号(不算整个表达式最外面一层)。所以如果你要是猜到了这一点可以直接使用动态规划从右到左扫这个字符串,记录每一层栈中的内容。最多三层栈,每层栈最多两个比特,一共 $6^3+6^2+6=258$ 种状态。大概也能过。 不知道有没有什么奇怪的乱搞可以搜过去。不过我还是欢迎吧。
题目4282 [THUPC 2025 Final] 一个 01 串,n 次三目运算符,最后值为 1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
评论
2026-01-29 18:37:59
|
|
|
引言今年命题会的时候,我们惊奇地发现今年的模拟题还没有着落。 于是我翻出了这个压箱底的 idea,当作一个中模拟。 idea 恰如其分来自在你清食堂的吃饭经历,获得了大家的一致认同。 时限只开 3s 是因为有 100 个点,开太久会更严重地卡评测的。std 跑了 1.6s。 比赛情况本题的完整版本预期难度是 medium,不过我个人认为是 easy+(?)。 丝路市西套村代表队获得了本题首杀! 本题大约有一半的队伍通过了本题。 同时,不少夺冠热门队伍在本题上获得了大量罚时。 题意简述食堂餐桌座位分布在第一象限网格每个 $3 \times 3$ 完整格子右上角的 $2 \times 2$ 格子,剩下的部分为走廊。 每次可以从一个走廊格子走到四连通相邻格子。 每次一名顾客从最左下角的格子出发,试图找到最优的一个满足自己容忍条件的空座位。容忍条件形如桌子上坐了几人以及自己因此应该去哪里(请参考原题面)。 此外还会有部分座位突然出现或消失顾客,也即状态翻转。 输出每次顾客坐到了哪里,以及突然变化的顾客是来是去。 操作次数 $q$ 不超过 $5 \times 10^5$。第二类操作值域不超过 $10^4$ 且总是修改在餐桌处。3s/1GB。 思路本题总体思路比较简单,这里直接给出完整版正解做法。 注意到第一类操作可能遇上的下标范围是 $O(\sqrt{q})$ 级别的,我们不妨考虑做预处理。 观察到其优先顺序是固定的,我们可以预先排序得到各个餐桌格子的优先顺序。这个排序可以通过数学方法或者 bfs 做到线性。 考虑第一类操作,我们可以用 set 或可删堆(对顶堆)存一下每个满足对应条件的位置。 第二类操作对于下标超界的部分也可以单独拿一个 set 存;没超界的部分可以和前面的部分使用同一套方法处理。 不用太多卡常,验题人开了八九个 set 都过了。std 不到 2kb。 本题非常善良,值域只开 $10^4$ 是为了方便压位(记得用 $10001$ 压)。没有特意卡 umap/bitset 之类的东西,应该是可以轻松过的。 总结
题目4281 [THUPC 2025 Final] 食堂
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
评论
2026-01-29 18:37:36
|