重複の可能性:
C++でのダム8クイーンの問題
こんにちは私はこの質問に出くわしました**
チェス盤に8つの王を配置するすべての方法を印刷するアルゴリズムを記述して、同じ行、列、対角線を持つものがないようにします。
****
//initialize chess[i][j] to 0;
int king=100; //any other number except 0/1
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
//select any one position for the first column... lets start with j=0,i=0
if(chess[i][j]!=1)
chess[i][j]=king;
//now we should cross all rows with value i and column with value j
chess[i][]=1;
print(when chess[][]=king)
// we cannot enter king if chess[][]=1
}
}
対角部分も確認する方法は?また、考えられるすべてのケースを列挙する方法は?
事前に感謝します。