rt,这题dfs真的可以过吗......
PS:登号非本人,珂能没有AC
#include<bits/stdc++.h>
using namespace std;
int a[100][100],b[100][100],l[100][100],r[100][100];
void dfs(int x,int y){
if(a[x][y]!=0){
if(x==9&&y==9){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cout<<a[i][j]<<' ';
}
cout<<endl;
}
}
if(y==9) dfs(x+1,1);
else dfs(x,y+1);
}
if(a[x][y] == 0){
for(int i = 1;i<=9;i++){
if(b[x][i]&&l[y][i]&&r[(x-1)/3*3+(y-1)/3+1][i]){
a[x][y] = i;
b[x][i] = 0;
l[y][i] = 0;
r[(x-1)/3*3+(y-1)/3+1][i] = 0;
if(x==9&&y==9){
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cout<<a[i][j]<<' ';
}
cout<<endl;
}
}
if(y==9)dfs(x+1,1);
else dfs(x,y+1);
a[x][y] = 0;
b[x][i] = 1;
l[y][i] = 1;
r[(x-1)/3*3+(y-1)/3+1][i] = 1;
}
}
}
}
int main(){
for(int i = 1;i<=10;i++){
for(int j = 1;j<=10;j++){
b[i][j] = 1;
l[i][j] = 1;
r[i][j] = 1;
}
}
for(int i=1;i<=9;i++){
for(int j=1;j<=9;j++){
cin>>a[i][j];
if(a[i][j]>0){
b[i][a[i][j]] = 0;
l[j][a[i][j]] = 0;
r[(i-1)/3*3+(j-1)/3+1][a[i][j]] = 0;
}
}
}
dfs(1,1);
return 0;
}