Light Up is a puzzle set in a rectangular board divided in smaller squares. Some squares in the board are ``empty'' (white squares the figure below), some squares are ``barriers'' (dark squares in the figure below). A barrier square may have an integer number i associated to it (0 <= i <= 4).
Figure 2: (a) Puzzle with 6 rows, 7 columns and 7 barriers; (b) a solution to the puzzle.
In this puzzle the goal is to ``light up'' all the empty squares by placing lamps in some of them (lamps are depicted as circles in the figure). Each lamp illuminates the square it is on, plus all squares in line with it, horizontally or vertically, up to a barrier square or the board end.
A winning configuration satisfies the following conditions:
- all empty squares must be lit;
- no lamp may be lit by another lamp;
- all numbered barrier squares must have exactly that number of lamps adjacent to them (in the four squares above, below, and to the side);
- non-numbered barrier squares may have any number of lamps adjacent to them.
You must write a program to determine the smallest number of lamps that are needed to reach a winning configuration.