#P1745. Constructing 2-SAT Constraints for Exactly Three Assignments
Constructing 2-SAT Constraints for Exactly Three Assignments
Constructing 2-SAT Constraints for Exactly Three Assignments
We are given Boolean variables that can take values (false) or (true). A 2-SAT constraint is a logical implication of the form , where both and are literals (either or its negation ). Recall that is logically equivalent to , and the constraint is satisfied if this clause evaluates to true.
You are given three distinct assignments (each a sequence of 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 (the number of constraints), followed by 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 is true) or !xk
(meaning 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 unwanted assignments. For each unwanted assignment , one can find a clause of two literals (written in implication form) that is satisfied by all three given assignments and falsified by . More precisely, for some pair of distinct indices and a choice of literals and (where is either x_i
or !x_i
and similarly for ), 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 , at least one of or evaluates to true, but for the unwanted assignment 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 is small enough – and indeed the restriction forces 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 (). The next three lines each contain space-separated integers (either 0 or 1), representing the three distinct assignments that satisfy the (hidden) 2-SAT formula.
outputFormat
First, output an integer indicating the number of constraints. Then output 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>