Logical Expression
题目描述
给定 N 个字符串 S1,…,SN,每个字符串为 AND 或 OR。
求有多少个长度为 N+1 的元组 (x0,…,xN),其中每个元素为 True 或 False,使得以下计算得到 yN 为 True:
y0=x0;
对于 i≥1,若 Si 为 AND,则 yi=yi−1∧xi,若 Si 为 OR,则 yi=yi−1∨xi。
这里,a∧b 和 a∨b 是逻辑运算符。
输入格式
输入从标准输入给出,格式如下:
N
S1
⋮
SN
输出格式
输出答案。
2
AND
OR
5
5
OR
OR
OR
OR
OR
63
提示
1≤N≤60
Si 为 AND 或 OR。例如,如果 $(x_0,x_1,x_2)=(\text{True},\text{False},\text{True})$,我们有 y2=True,如下所示:
y0=x0=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}$
下面列出了所有 令 y2=True 的五个元组 (x0,x1,x2):
(True,True,True)
(True,True,False)
(True,False,True)
(False,True,True)
(False,False,True)
除全部为 False 的那个元组外,所有元组都使得 y5=True。
标签: AtCoder|abc189D
来源
AtCoder|abc189D