Look at the 8x8 grid below at left. In the rows and columns there are repeated numbers. Erasing 19 of them, we achieve the grid at right, that has no repeated numbers in any row, in any column.
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 5 | 7 | 1 | 2 | 5 | 4 | 4 | 3 | | | 7 | 1 | | 5 | | 4 | 3 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 4 | 3 | 1 | 2 | 7 | 5 | 6 | 3 | | 4 | 3 | | 2 | 7 | 5 | 6 | |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 5 | 5 | 3 | 4 | 2 | 1 | 7 | 8 | | | 5 | 3 | | 2 | | 7 | 8 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 6 | 6 | 2 | 7 | 3 | 3 | 3 | 1 | | 6 | | 2 | 7 | | 3 | | 1 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 3 | 2 | 5 | 6 | 9 | 1 | 8 | 6 | | 3 | 2 | 5 | | 9 | 1 | 8 | 6 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 2 | 1 | 3 | 4 | 6 | 2 | 5 | 2 | | | 1 | | 4 | 6 | | 5 | 2 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 9 | 8 | 4 | 1 | 4 | 6 | 2 | 3 | | 9 | 8 | 4 | 1 | | 6 | 2 | |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
| 7 | 5 | 6 | 5 | 8 | 5 | 1 | 4 | | 7 | | 6 | 5 | 8 | | 1 | 4 |
+---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+
Do the same with this 8x8 grid, erasing the minimum number of squares.
+---+---+---+---+---+---+---+---+
| 8 | 4 | 6 | 5 | 3 | 5 | 7 | 4 |
+---+---+---+---+---+---+---+---+
| 6 | 5 | 5 | 4 | 7 | 8 | 3 | 1 |
+---+---+---+---+---+---+---+---+
| 5 | 7 | 2 | 5 | 5 | 4 | 8 | 7 |
+---+---+---+---+---+---+---+---+
| 8 | 6 | 5 | 3 | 2 | 5 | 4 | 4 |
+---+---+---+---+---+---+---+---+
| 3 | 8 | 1 | 4 | 8 | 6 | 5 | 2 |
+---+---+---+---+---+---+---+---+
| 5 | 3 | 7 | 6 | 4 | 2 | 2 | 2 |
+---+---+---+---+---+---+---+---+
| 5 | 8 | 7 | 7 | 6 | 2 | 1 | 3 |
+---+---+---+---+---+---+---+---+
| 1 | 1 | 3 | 7 | 6 | 4 | 6 | 8 |
+---+---+---+---+---+---+---+---+
Note that (ignoring restrictions not listed in the problem) the numbers are independent from each other.
Considering only one number at a time, connect any number on the same row or column with an edge. Then the problem reduces to "delete the fewest nodes so no edge has both its endpoints remain", which likely has a set algorithm already.
In this case, we have restrictions on the input, so it becomes easier. Any number which doesn't have the same number in its row and column is dominated by one in the same row/column which does. For example, in the top row, the left 4 is dominated by the right 4, since the right 4 has another 4 a few spaces below. Thus, regardless of the rest of the solution, removing the right 4 is as good or better than removing the left 4.
|
Posted by Gamer
on 2008-08-21 17:04:55 |