不知为何,都不输出了 感谢各位大佬调整(膜拜)
#include<bits/stdc++.h>
using namespace std;
int mp[50][50];
int g[100][100]={
{0,0,0,0,0,0,0,0,0,0},
{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,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}
};
bool row[20][20],col[20][20],gong[20][20];
void dfs(int x,int y){
if(x==10){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cout<<mp[i][j]<<" ";
}
cout<<"\n";
}
exit(0);
}
if(!mp[x][y]){
for(int i=1;i<=9;i++){
if(!row[i][x]&&!col[i][y]&&!gong[i][g[x][y]]){
row[i][x]=col[i][y]=gong[i][g[x][y]]=1;
mp[x][y]=i;
if(y==9){
dfs(x+1,1);
}else{
dfs(x,y+1);
}
row[i][x]=col[i][y]=gong[i][g[x][y]]=0;
mp[x][y]=0;
}
}
}else{
if(y==9){
dfs(x+1,1);
}else{
dfs(x,y+1);
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cin>>mp[i][j];
row[mp[i][j]][i]=col[mp[i][j]][j]=gong[mp[i][j]][g[i][j]]=1;
}
}
dfs(1,1);
return 0;
}