logo AlgoBeat OnlineJudge
登录 注册

#206178. [NWRRC 2017] Boolean Satisfiability

内存限制:512 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Boolean satisfiability problem (SAT) is known to be a very hard problem in computer science. In this problem you are given a Boolean formula, and you need to find out if the variables of a given formula can be consistently replaced by the values true or false in such a way that the formula evaluates to true. SAT is known to be NP-complete problem. Moreover, it is NP-complete even in case of formula However, for example, SAT problem for formulae is in .

You can't use 'macro parameter character #' in math mode#SAT is the extension of SAT problem. In this problem you need to check if it is possible, and count the number of ways to assign values to variables. This problem is known to be You can't use 'macro parameter character #' in math mode#P-complete even for formulae. We ask you to solve You can't use 'macro parameter character #' in math mode#1-DNF-SAT, which is You can't use 'macro parameter character #' in math mode#SAT problem for formulae.

You are given a Boolean formula in form. It means that it is a disjunction (logical or) of one or more clauses, each clause is exactly one literal, each literal is either variable or its negation (logical not).

Formally:

A . . . a . . .

Your task is to find the number of ways to replace all variables with values true and false (all occurrences of the same variable should be replaced with same value), such that the formula evaluates to true.

输入格式

The only line of the input file contains a logical formula in form (not longer than symbols). Logical operations are represented by (disjunction) and The variables are . . . and . . . (uppercase and lowercase letters are different variables). The formula contains neither spaces nor other characters not mentioned in the grammar.

输出格式

Output a single integer -- the answer for You can't use 'macro parameter character #' in math mode#SAT problem for the given formula.

样例

样例输入 1

a

样例输出 1

1

样例输入 2

B|~B

样例输出 2

2

样例输入 3

c|~C

样例输出 3

3

样例输入 4

i|c|p|c

样例输出 4

7

数据范围与提示

Time limit: 3 s, Memory limit: 512 MB.