Knight's tour - MarisaOJ: Marisa Online Judge

Knight's tour

Time limit: 2000 ms
Memory limit: 256 MB
Given a chessboard of size $n \times m$, find a sequence of moves for a knight on a chessboard, such that the knight visits every square exactly once. Initially, you can place the knight at any position. ### Input - A single line contains two integers $n,m$. ### Output - Print a matrix of size $n\times m$ representing the order of visiting, starting from $1$. ### Constraints - $1 \le n,m \le 7$. ### Example Input: ``` 5 5 ``` Output: ``` 1 6 15 10 21 14 9 20 5 16 19 2 7 22 11 8 13 24 17 4 25 18 3 12 23 ```