简单版四皇后求讲解
#include<stdio.h>#include<stdlib.h>
int queen[4][4] = {0};
int main()
{
int i = 0;
int j = 0;
int queenFind(int , int);
queenFind(i,j);
printf("1");
getchar();
}
int queenFind(int i,int j)
{
int k,l;
queen[i][j] = 1;
if(queen[0][j] + queen[1][j] + queen[2][j] + queen[3][j] == 1 && queen[i][0] + queen[i][1] + queen[i][2] + queen[i][3] == 1)
{
if(queenFind(i + 1,0) || queenFind(i + 1,1) || queenFind(i + 1,2) || queenFind(i + 1,3))
{
if(i >= 4)
{
for(k = 0;k < 4;k++)
{
for(l = 0;l < 4;l++)
{
printf("%d ", queen[l][k]);
}
printf("\n");
}
getchar();
exit(0);
}
return 1;
}
else
{
queen[i][j] = 0;
return 0;
}
}
}
这个四皇后只能判断横着和竖着,怎么也改不对,求讲解,最好能完成完全版,拜谢!!