An array with destructive updates (IO/ST) may help. You can also look into the exact cover problem and dancing links. If I recall correctly, this problem can be transformed to a 729*324 matrix.