My open homework about algorithms: (see attached file)

We have n * n grid squares being colored with m colors. (n >= 5; n <= 20; m <= 8))
For example (picture):




The first row displays...