A9995 | Boolean Function
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
In this problem we consider Boolean functions of four variables $A,B,C,D$ . Variables $A,B,C$ and $D$ are logical and can take values 0 or 1. We will define a function using the following grammar:
<expression> ::= <variable> | (<expression>) <operator> (<expression>)
<variable> ::= 'A' | 'B' | 'C' | 'D' | 'a' | 'b' | 'c' | 'd'
<operator> ::= '&' | '|'
Here large letters $A,B,C,D$ represent variables, and small letters represent their negations. For example, if $A=1$ , then character 'A' corresponds to value 1, and value character 'a' corresponds to value 0. Here character '&' corresponds to the operation of logical AND, character '|' corresponds to the operation of logical OR.
You are given expression $s$ , defining function $f$ , where some operations and variables are missing. Also you know the values of the function $f(A,B,C,D)$ for some $n$ distinct sets of variable values. Count the number of ways to restore the elements that are missing in the expression so that the resulting expression corresponded to the given information about function $f$ in the given variable sets. As the value of the result can be rather large, print its remainder modulo $10^{9}+7$ .
<expression> ::= <variable> | (<expression>) <operator> (<expression>)
<variable> ::= 'A' | 'B' | 'C' | 'D' | 'a' | 'b' | 'c' | 'd'
<operator> ::= '&' | '|'
Here large letters $A,B,C,D$ represent variables, and small letters represent their negations. For example, if $A=1$ , then character 'A' corresponds to value 1, and value character 'a' corresponds to value 0. Here character '&' corresponds to the operation of logical AND, character '|' corresponds to the operation of logical OR.
You are given expression $s$ , defining function $f$ , where some operations and variables are missing. Also you know the values of the function $f(A,B,C,D)$ for some $n$ distinct sets of variable values. Count the number of ways to restore the elements that are missing in the expression so that the resulting expression corresponded to the given information about function $f$ in the given variable sets. As the value of the result can be rather large, print its remainder modulo $10^{9}+7$ .
输入格式
The first line contains expression $s$ ( $1<=|s|<=500$ ), where some characters of the operators and/or variables are replaced by character '?'.
The second line contains number $n$ ( $0<=n<=2^{4}$ ) — the number of integers sets for which we know the value of function $f(A,B,C,D)$ . Next $n$ lines contain the descriptions of the sets: the $i$ -th of them contains five integers $a_{i},b_{i},c_{i},d_{i},e_{i}$ ( $0<=a_{i},b_{i},c_{i},d_{i},e_{i}<=1$ ), separated by spaces and meaning that $f(a_{i},b_{i},c_{i},d_{i})=e_{i}$ .
It is guaranteed that all the tuples ( $a_{i},b_{i},c_{i},d_{i}$ ) are distinct.
The second line contains number $n$ ( $0<=n<=2^{4}$ ) — the number of integers sets for which we know the value of function $f(A,B,C,D)$ . Next $n$ lines contain the descriptions of the sets: the $i$ -th of them contains five integers $a_{i},b_{i},c_{i},d_{i},e_{i}$ ( $0<=a_{i},b_{i},c_{i},d_{i},e_{i}<=1$ ), separated by spaces and meaning that $f(a_{i},b_{i},c_{i},d_{i})=e_{i}$ .
It is guaranteed that all the tuples ( $a_{i},b_{i},c_{i},d_{i}$ ) are distinct.
输出格式
In a single line print the answer to the problem.
输入输出样例
输入 #1
? 2 1 0 1 0 1 0 1 1 0 1
输出 #1
2
输入 #2
(A)?(?) 1 1 1 0 0 0
输出 #2
4
输入 #3
((?)&(?))|((?)&(?)) 0
输出 #3
4096
输入 #4
b 1 1 0 1 1 1
输出 #4
1
In the first sample the two valid expressions are 'C' and 'd'.
In the second sample the expressions look as follows: '(A)&(a)', '(A)&(b)', '(A)&(C)', '(A)&(D)'.
In the second sample the expressions look as follows: '(A)&(a)', '(A)&(b)', '(A)&(C)', '(A)&(D)'.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted