+ 23
Knight_chess travelling problem [time limit exceeded]
here is the code , time limit exceeds for coordinates other than coordinates of corner cells , might because not corner cells means ... possibilities in all 4 directions from initial coordinate , but in extreme corner , 2 directions gets automatically eliminated for initial move ... so it takes less time https://code.sololearn.com/c53fHObgt9Um/?ref=app here is link to challenge : https://www.sololearn.com/Discuss/888930/?ref=app 👉any way to improve it ???
2 Antworten
+ 21
Buddy, if we will keep your approach to the problem, your code is perfect 👌
But, backtracking is not the best solution for the Knight’s tour problem.
Note: on an 8 × 8 board, there are exactly 26,534,728,821,064 directed closed tours.
In order to speed up the process, selecting to which field you have to jump first makes a huge difference in total performance. If you jump to the field which has the least options, you can speed up the total process by orders of magnitude (this is known as Warnsdorff’s algorithm). Otherwise, jump to the "wrong" field (field with a lot options) can cause a time limit exceed.
So, you have two choices:
1. do not change anything
2. to change the approach to the problem
+ 5
thnx ☺ @LukArToDo,
will think new better approach soon