Lights Out on Bob's Panel
Bob rigged a panel of lamps above Alice's desk as a prank, and right now some of them are lit. Next to the panel is a row of switches: each switch is wired to a fixed set of lamps, and pressing it flips the on/off state of exactly those lamps, nothing else. Pressing the same switch twice undoes itself, so Alice will press each switch at most once.
Alice wants every lamp off, using as few switch presses as possible. Bob, being Bob, will demand she read out exactly which switches she used — so among all plans that use the fewest presses, Alice wants the one whose sorted list of switch numbers is lexicographically smallest (compare the two sorted lists term by term; the first list with the smaller entry at the first position where they differ wins).
Formally: there are m lamps, numbered 1 to m, each currently on or off, and n switches,
numbered 1 to n. Switch i toggles a fixed, known subset of the lamps. Find a subset of
switches, each used at most once, such that pressing all of them (in any order — toggling is
commutative) leaves every lamp off, using the fewest switches possible. Among all subsets achieving
that minimum, output the lexicographically smallest one, or -1 if no subset of switches can turn
every lamp off.
Input
The first line contains two integers m and n (1 ≤ m ≤ 20, 1 ≤ n ≤ 20).
The second line contains a string of length m of 0/1 characters: the current state of the
lamps. Its j-th character (1-indexed) is 1 if lamp j is currently lit, 0 if it is off.
Each of the next n lines contains a string of length m of 0/1 characters describing one
switch, in order: the i-th such line describes switch i, and its j-th character is 1 if
pressing switch i toggles lamp j, 0 if it leaves lamp j alone.
Output
If no subset of switches turns every lamp off, print a single line containing -1.
Otherwise, print the minimum number of switches k needed on the first line. If k > 0, print on a
second line the indices of the chosen switches, in increasing order and separated by single spaces:
the lexicographically smallest such minimum-size subset (if k = 0, because all lamps already start
off, print no second line).
Notes
In the first example, pressing switch 2 alone toggles lamps 1 and 3, which are exactly the lit
ones, so one press suffices.
In the second example, no combination of the two switches can ever change lamp 2's state (neither
switch touches it), so the single lit lamp can never be turned off.