|
|
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
|