4th Balkan Olympiad in Informatics
Nicosia, Cyprus, 19-25 October 1997


Day 1 - Problem 3 (Heads and tails)



A NxN matrix (where N<=10) of coins is given, some heads up and some tails up. A player must flip coins so as to achieve an all tails configuration. However, when a player flips a particular coin, each rectilinearly adjacent neighbors (i.e. its left, right, top and bottom neighbors, if they exist), also flip over.
The problem is, given an initial configuration, to achieve an all tails matrix by flipping the minimum number of coins. Note that by flip we mean "point to a coin, and change it and its neighbors".
Time-limit for each test: 20 seconds.
Maximal score: 40 points