Thuật toán Quay lui Tìm lời giải cho bài toán 8 (hoặc N) quân hậu
(chịu khó dịch thành tiếng Việt nhé)
1) Start in the left most column
2) If all queens are placed
return true
3) Try all rows in the current column. Do following for every tried row.
a) If the queen can be placed safely in this row then mark this [row,
column] as part of the solution and recursively check if placing
queen here leads to a solution.
b) If placing queen in [row, column] leads to a solution then return
true.
c) If placing queen doesn't lead to a solution then umark this [row,
column] (Backtrack) and go to step (a) to try other rows.
3) If all rows have been tried and nothing worked, return false to trigger
back tracking
Video hướng dẫn lập trình: