#aBC189Did586. [ABC189D] Logical Expression

[ABC189D] Logical Expression

AT_abc189_d [ABC189D] Logical Expression

题目描述

给定 NN 个字符串 S1,,SNS_1,\ldots,S_N,每个字符串为 ANDOR

请计算有多少组 N+1N+1 个变量 (x0,,xN)(x_0,\ldots,x_N),每个变量的取值为 True\text{True}False\text{False},使得按照如下方式计算后,yNy_N 的值为 True\text{True}

  • y0=x0y_0 = x_0
  • i1i \geq 1 时,若 SiS_iAND,则 yi=yi1xiy_i = y_{i-1} \land x_i;若 SiS_iOR,则 yi=yi1xiy_i = y_{i-1} \lor x_i

其中 aba \land b 表示 aabb 的逻辑与,aba \lor b 表示 aabb 的逻辑或。

输入格式

输入以如下格式从标准输入读入:

NN
S1S_1
\vdots
SNS_N

输出格式

请输出答案。

输入输出样例 #1

输入 #1

2
AND
OR

输出 #1

5

输入输出样例 #2

输入 #2

5
OR
OR
OR
OR
OR

输出 #2

63

说明/提示

限制条件

  • 1N601 \leq N \leq 60
  • SiS_iANDOR

样例解释 1

例如,当 $(x_0,x_1,x_2)=(\text{True},\text{False},\text{True})$ 时:

  • y0=x0=Truey_0 = x_0 = \text{True}
  • $y_1 = y_0 \land x_1 = \text{True} \land \text{False} = \text{False}$
  • $y_2 = y_1 \lor x_2 = \text{False} \lor \text{True} = \text{True}$

因此 y2y_2 的值为 True\text{True}

使 y2y_2True\text{True}(x0,x1,x2)(x_0,x_1,x_2) 的组合共有:

  • (True,True,True)(\text{True},\text{True},\text{True})
  • (True,True,False)(\text{True},\text{True},\text{False})
  • (True,False,True)(\text{True},\text{False},\text{True})
  • (False,True,True)(\text{False},\text{True},\text{True})
  • (False,False,True)(\text{False},\text{False},\text{True})

55 种。

样例解释 2

除了所有变量均为 False\text{False} 的情况外,其余 2612^6-1 种组合都能使 y5y_5True\text{True}

由 ChatGPT 4.1 翻译