#P1745. Constructing 2-SAT Constraints for Exactly Three Assignments

    ID: 15030 Type: Default 1000ms 256MiB

Constructing 2-SAT Constraints for Exactly Three Assignments

Constructing 2-SAT Constraints for Exactly Three Assignments

We are given nn Boolean variables x1,x2,,xnx_1, x_2, \cdots, x_n that can take values 00 (false) or 11 (true). A 2-SAT constraint is a logical implication of the form aba\to b, where both aa and bb are literals (either xix_i or its negation !xi!x_i). Recall that aba\to b is logically equivalent to ¬ab\lnot a\lor b, and the constraint is satisfied if this clause evaluates to true.

You are given three distinct assignments (each a sequence of nn bits) that satisfy some unknown 2‐SAT formula. It is known that these three assignments are the only assignments satisfying that formula. Your task is to output any list of at most 500 2‐SAT constraints that have exactly these three assignments as their solutions.

A valid output consists of an integer mm (the number of constraints), followed by mm lines. Each line describes a constraint of the form

a -> b

where a and b are literals. In our notation a literal is either xk (meaning xkx_k is true) or !xk (meaning xkx_k is false), with indices starting at 1.

One way to solve this problem is to eliminate every assignment that is not one of the three given ones. Notice there are 2n32^n-3 unwanted assignments. For each unwanted assignment UU, one can find a clause of two literals (written in implication form) that is satisfied by all three given assignments and falsified by UU. More precisely, for some pair of distinct indices i,ji,j and a choice of literals LiL_i and LjL_j (where LiL_i is either x_i or !x_i and similarly for LjL_j), the clause

(L_i or L_j)  (*),

which can be written in implication form as

(not L_i) -> L_j

is chosen so that for every allowed assignment DD, at least one of LiL_i or LjL_j evaluates to true, but for the unwanted assignment UU both evaluate to false. If one does this for every unwanted assignment, then the only assignments that satisfy all the constraints will be exactly the three given ones. (It can be shown that when nn is small enough – and indeed the restriction m500m\le500 forces nn to be relatively small – such pairs exist.)

Your program should read the three assignments and output a valid list of constraints constructed in this way. The answer may be any correct list of at most 500 valid constraints.

inputFormat

The first line contains an integer nn (2n82\le n\le 8). The next three lines each contain nn space-separated integers (either 0 or 1), representing the three distinct assignments that satisfy the (hidden) 2-SAT formula.

outputFormat

First, output an integer mm indicating the number of constraints. Then output mm lines, each line containing a constraint in the form a -> b where a and b are literals. The generated list of constraints must be such that its only solutions (assignments satisfying all constraints) are exactly the three given assignments.

sample

2
0 0
0 1
1 0
1

x1 -> !x2

</p>