#ABC189D. 逻辑表达式

逻辑表达式

逻辑表达式

题目描述

给定 NN 个字符串 S1,…,SNS_1,\ldots,S_N。每个字符串都是 AND 或 OR。

求值为 True\text{True} 或 False\text{False} 的 N+1N+1 个变量的组 (x0,…,xN)(x_0,\ldots,x_N) 中,按以下方式计算时能使 yNy_N 为 True\text{True} 的个数。

  • y0=x0y_0=x_0
  • 当 i≥1i\geq 1 时,若 SiS_i 为 AND,则 yi=yi−1∧xiy_i=y_{i-1} \land x_i;若 SiS_i 为 OR,则 yi=yi−1∨xiy_i=y_{i-1} \lor x_i

这里 a∧ba \land b 表示 aa 与 bb 的逻辑与(AND),a∨ba \lor b 表示 aa 与 bb 的逻辑或(OR)。

输入格式

输入按以下格式从标准输入给出:

NN
S1S_1
⋮\vdots
SNS_N

输出格式

输出答案。

样例

2
AND
OR
5

例如,当 $(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_2 为 True\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 种,即全部。

5
OR
OR
OR
OR
OR
63

除去全部为 False\text{False} 的情况,共 26−12^6-1 种情况下 y5y_5 为 True\text{True}。

数据范围

  • 1≤N≤601 \leq N \leq 60
  • SiS_i 是 AND 或 OR
难度 普及+/提高-
通过率 —
尝试 0
通过 0
ID
2067
类型
传统题
Time Limit
2000ms
Memory Limit
1024MiB
上传者
标签