21740_Formula

2022-5-16 18:20| 发布者: Hocassian| 查看: 25| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505807806200-Problem List-采集的数据-后羿采集器.html

Pro.ID

21740

Title

Formula

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21740

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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:
    • Variables — letters from ‘a’ to ‘z’ and from ‘A’ to ‘Z’;

    • Parentheses — if E is a formula, then (E) is another;

    • Negation — E is a formula for any formula E;

    • Conjunction — E1 ^ E2 ^ ... ^ En.

    • Disjunction — E1 V E2 V ... V En.

    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:
    • Variables — letters from ‘a’ to ‘z’ and from ‘A’ to ‘Z’;

    • Parentheses — if E is a formula, then (E) is another;

    • Negation — E is a formula for any formula E;

    • Conjunction — E1 ^ E2 ^ ... ^ En.

    • Disjunction — E1 V E2 V ... V En.

    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

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部