SZ-G6DP17. 【GESP强化 六级】逻辑表达式

提交1 通过1
通过率100%
时间限制2000ms
内存限制256MiB
    ID: 11531 传统题 2000ms 256MiB 尝试: 1 已通过: 1 难度: 普及- 上传者: 标签>GESPGESP强化C++c++编程题简单序列型DP一维DP方案计数1星

题目描述

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

请计算有多少组 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
  • 当 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 的逻辑与,a∨ba \lor b 表示 aa 与 bb 的逻辑或。

输入格式

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

NN
S1S_1
⋮\vdots
SNS_N

输出格式

请输出答案。

2
AND
OR
5
5
OR
OR
OR
OR
OR
63
2
AND
AND
1

说明/提示

样例解释 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_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 种。

样例解释 2

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

限制条件

  • 1≤N≤601 \leq N \leq 60
  • SiS_i 为 AND 或 OR