Pro.ID21740 TitleFormula Title链接http://10.20.2.8/oj/exercise/problem?problem_id=21740 AC0 Submit0 Ratio- 时间&空间限制描述Nick is a mathematician and his speciality is Boolean logic, especially repetition-free formulas. Formula is repetition-free if each variable occurs in the formula only once. Let us fix the syntax of considered logical formulae:
The operations are listed from the highest priority to the lowest. An assignment is a function that maps each variable to its Boolean value. Assignment satisfies Boolean formula F if the value of F for this assignment is true. The problem is to count the number of assignments that satisfy a given repetition-free Boolean formula. 输入The only line of the input file contains the Boolean formula — a string consisting of characters ‘a’..‘z’, ‘A’..‘Z’, ‘(’, ‘)’, ‘~’, ‘&’ and ‘|’. The last three tokens stand for , ^ and V respectively. Uppercase and lowercase letters represent different variables. Tokens can be separated by an arbitrary number of spaces. The line contains 1 000 characters at most. The formula in the file is a syntactically correct repetition-free formula. 输出Description Nick is a mathematician and his speciality is Boolean logic, especially repetition-free formulas. Formula is repetition-free if each variable occurs in the formula only once. Let us fix the syntax of considered logical formulae:
The operations are listed from the highest priority to the lowest. An assignment is a function that maps each variable to its Boolean value. Assignment satisfies Boolean formula F if the value of F for this assignment is true. The problem is to count the number of assignments that satisfy a given repetition-free Boolean formula. Input The only line of the input file contains the Boolean formula — a string consisting of characters ‘a’..‘z’, ‘A’..‘Z’, ‘(’, ‘)’, ‘~’, ‘&’ and ‘|’. The last three tokens stand for , ^ and V respectively. Uppercase and lowercase letters represent different variables. Tokens can be separated by an arbitrary number of spaces. The line contains 1 000 characters at most. The formula in the file is a syntactically correct repetition-free formula. Output The first line of the output file must contain the number of variable assignments that satisfy the repetitionfree formula given in the input file. Sample Input Sample #1 A | a & b Sample #2 ~a&~c&~m Sample Output Sample #1 5 Sample #2 1 Source 样例输入Sample #1 A | a & b Sample #2 ~a&~c&~m 样例输出Sample #1 5 Sample #2 1 作者 |