| NOIP 2023 |
|---|
| Finished |
小 L 今天学习了 Kleene 三值逻辑。 在三值逻辑中,一个变量的值可能为:真($$$\mathit{True}$$$,简写作 $$$\mathit{T}$$$)、假($$$\mathit{False}$$$,简写作 $$$\mathit{F}$$$)或未确定($$$\mathit{Unknown}$$$,简写作 $$$\mathit{U}$$$)。 在三值逻辑上也可以定义逻辑运算。由于小 L 学习进度很慢,只掌握了逻辑非运算 $$$\lnot$$$,其运算法则为: $$$$$$\lnot \mathit{T} = \mathit{F}, \lnot \mathit{F} = \mathit{T}, \lnot\mathit{U} = \mathit{U}.$$$$$$ 现在小 L 有 $$$n$$$ 个三值逻辑变量 $$$x_1,\cdots, x_n$$$。小 L 想进行一些有趣的尝试,于是他写下了 $$$m$$$ 条语句。语句有以下三种类型,其中 $$$\leftarrow$$$ 表示赋值:
本题的测试点包含有多组测试数据。 输入的第一行包含两个整数 $$$c$$$ 和 $$$t$$$,分别表示测试点编号和测试数据组数。对于样例,$$$c$$$ 表示该样例与测试点 $$$c$$$ 拥有相同的限制条件。 接下来,对于每组测试数据:
对于每组测试数据输出一行一个整数,表示所有符合条件的赋初值方案中,$$$\mathit{Unknown}$$$ 变量个数的最小值。
1 3 3 3 - 2 1 - 3 2 + 1 3 3 3 - 2 1 - 3 2 - 1 3 2 2 T 2 U 2
0 3 1
【样例解释 #1】
第一组测试数据中,$$$m$$$ 行语句依次为
- $$$x_2 \leftarrow \lnot x_1$$$; - $$$x_3 \leftarrow \lnot x_2$$$; - $$$x_1 \leftarrow x_3$$$。
一组合法的赋初值方案为 $$$x_1 = \mathit{T}, x_2 = \mathit{F}, x_3 = \mathit{T}$$$,共有 $$$0$$$ 个$$$\mathit{Unknown}$$$ 变量。因为不存在赋初值方案中有小于 $$$0$$$ 个$$$\mathit{Unknown}$$$ 变量,故输出为 $$$0$$$。
第二组测试数据中,$$$m$$$ 行语句依次为
- $$$x_2 \leftarrow \lnot x_1$$$; - $$$x_3 \leftarrow \lnot x_2$$$; - $$$x_1 \leftarrow \lnot x_3$$$。
唯一的赋初值方案为 $$$x_1 = x_2 = x_3 = \mathit{U}$$$,共有 $$$3$$$ 个$$$\mathit{Unknown}$$$ 变量,故输出为 $$$3$$$。
第三组测试数据中,$$$m$$$ 行语句依次为
- $$$x_2 \leftarrow \mathit{T}$$$; - $$$x_2 \leftarrow \mathit{U}$$$;
一个最小化 $$$\mathit{Unknown}$$$ 变量个数的赋初值方案为 $$$x_1 = \mathit{T}, x_2 = \mathit{U}$$$。$$$x_1 = x_2 = \mathit{U}$$$ 也是一个合法的方案,但它没有最小化 $$$\mathit{Unknown}$$$ 变量的个数。
【数据范围】
对于所有测试数据,保证:
| Name |
|---|


