深搜:(赋自己一点点解释,希望有帮助)
#include<bits/stdc++.h>
//万能头文件,但是有些系统不能使用
using namespace std;
int mp[9][9];//用来存原始数据,需要设为全局变量
bool Isok(int n)
{
int row=n/9;//找到所在行
int col=n%9;//列
for(int i=0;i<9;i++){
if(mp[row][i]==mp[row][col]&&i!=col)
return false;
}
for(int i=0;i<9;i++){
if(mp[i][col]==mp[row][col]&&i!=row)
return false;
}
//判断行和列是否有重复
int temprow=row/3*3;
int tempcol=col/3*3;
for(int i=temprow;i<temprow+3;i++){
for(int j=tempcol;j<tempcol+3;j++){
if(mp[i][j]==mp[row][col]&&i!=row&&j!=col)
return false;
}
}
//判断小格里面是否重复
return true;
}
void DFS(int n)
{
if(n==81){//深搜完毕