#include<bits/stdc++.h>
using namespace std;
int g[10][10]={
{0,1,1,1,2,2,2,3,3,3},
{0,1,1,1,2,2,2,3,3,3},
{0,1,1,1,2,2,2,3,3,3},
{0,4,4,4,5,5,5,6,6,6},
{0,4,4,4,5,5,5,6,6,6},
{0,4,4,4,5,5,5,6,6,6},
{0,7,7,7,8,8,8,9,9,9},
{0,7,7,7,8,8,8,9,9,9},
{0,7,7,7,8,8,8,9,9,9}};
int row[10][10],col[10][10],small[10][10],maze[10][10];
bool flag=0;
void dfs(int x,int y)
{
if(flag) return;
if(y==10) x+=1,y=1;
if(x==10)
{
flag=true;
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++) cout<<maze[i][j]<<" ";
cout<<endl;
}
return;
}
if(maze[x][y]) dfs(x,y+1);
else
{
for(int k=1;k<=9;k++)
{
if(row[x][k]==0&&col[y][k]==0&&small[g[x][y]][k]==0)
{
maze[x][y]=k;
row[x][k]=1;
col[y][k]=1;
small[g[x][y]][k]=1;
dfs(x,y+1);
maze[x][y]=0;
row[x][k]=0;
col[y][k]=0;
small[g[x][y]][k]=0;
}
}
}
return;
}
int main()
{
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
{
int t;
cin>>t;
maze[i][j]=t;
if(t)
{
row[i][t]=1;
col[j][t]=1;
small[g[i][j]][t]=1;
}
}
dfs(1,1);
return 0;
}
为什么样例过不了QAQ