21659_MAX-2-SAT

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

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

Pro.ID

21659

Title

MAX-2-SAT

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    In propositional logic, a variable pi may take values 0 (for false) or 1 (for true). A literal lj is a variable pi or its negation pi . A clause is a disjunction of literals, and a CNF formula is a conjunction of clauses. An assignment of truth values to the propositional variables satisfies a literal pi if pi takes the value 1 and satisfies a literal pi. if pi takes the value 0, satisfies a clause if it satisfies at least one literal of the clause, and satisfies a CNF formula if is satisfies all the clauses of the formula.

    The MAX-SAT problem for a CNF formula is the problem of finding an assignment of values to propositional variables that maximizes the number of satisfied clauses. When all the clauses have 2 literals per clause, it is called MAX-2-SAT.

    Now, you are asked to solve the MAX-2-SAT problem.

    输入

    The first line of the input is a positive integer T ( 0 < T ≤ 20 ). T is the number of test cases followed.

    For each test case, the first line contains two integers N ( 1 < N < 31 ) and M ( 1 < M < 201 ). N is the number of variables and M is the number of clauses in the CNF formula. Then M clauses followed. Each of these clauses contains two integer x, y ( -Nx, yN ) Positive numbers denote the corresponding variables. Negative numbers denote the negations of the corresponding variables.

    输出

    Description

    In propositional logic, a variable pi may take values 0 (for false) or 1 (for true). A literal lj is a variable pi or its negation pi . A clause is a disjunction of literals, and a CNF formula is a conjunction of clauses. An assignment of truth values to the propositional variables satisfies a literal pi if pi takes the value 1 and satisfies a literal pi. if pi takes the value 0, satisfies a clause if it satisfies at least one literal of the clause, and satisfies a CNF formula if is satisfies all the clauses of the formula.

    The MAX-SAT problem for a CNF formula is the problem of finding an assignment of values to propositional variables that maximizes the number of satisfied clauses. When all the clauses have 2 literals per clause, it is called MAX-2-SAT.

    Now, you are asked to solve the MAX-2-SAT problem.

    Input

    The first line of the input is a positive integer T ( 0 < T ≤ 20 ). T is the number of test cases followed.

    For each test case, the first line contains two integers N ( 1 < N < 31 ) and M ( 1 < M < 201 ). N is the number of variables and M is the number of clauses in the CNF formula. Then M clauses followed. Each of these clauses contains two integer x, y ( -Nx, yN ) Positive numbers denote the corresponding variables. Negative numbers denote the negations of the corresponding variables.

    Output

    For each test case output the maximum number of satisfied clauses in a single line.

    Sample Input

    1
    2 4
    -2 1
    2 1
    2 -1
    -1 -2

    Sample Output

    3

    Source

    样例输入

    1
    2 4
    -2 1
    2 1
    2 -1
    -1 -2

    样例输出

    3

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部