问题描述
这是我通过传递args:0和board从主函数调用它时返回的输出,其中0是要从其开始的行号,而board是一个填充有零的4x4电路板:
9 1 1 1
1 1 9 1
1 1 1 1
1 0 1 1
注意:9表示皇后,1表示受到皇后攻击的牢房,0是既没有女王也不受到皇后攻击的安全牢房。
bool queen_placer(int row,std::vector<std::vector<int>> &board)
{
if (row == board.size())
{
return true;
}
for (int col = 0; col < board[0].size(); col++)
{
bool safe = is_valid(row,col,board); //is_valid returns true if the position doesn't contain any queen and is not attacked by any queen
if (safe)
{
board[row][col] = 9;
value_assigner(row,board); //value assigner just assigns the attack values of the queen so placed
if (queen_placer(row++,board))
{
return true;
}
else
{
continue;
}
}
}
return false;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)