rt,#2 #3 #4 WA,其它 TLE
#include <iostream>
using namespace std;
int a[10][10];
bool v[10][10], g[10][10], h[10][10];
void dfs(int step){
if (step > 81){
for (int i = 1;i <= 9;i++){
for (int j = 1;j <= 9;j++) cout << a[i][j] << " ";
cout << endl;
}
return;
}
int x = step / 9, y = step % 9, z = x / 3 * 3 + y / 3;
if (a[x][y] != 0) dfs(step + 1);
else
for (int i = 1;i <= 9;i++){
if (v[x][i] || g[y][i] || h[z][i]) continue;
v[x][i] = g[y][i] = h[z][i] = 1;
a[x][y] = i;
dfs(step + 1);
v[x][i] = g[y][i] = h[z][i] = 0;
a[x][y] = 0;
}
}
int main(){
for (int i = 1;i <= 9;i++)
for (int j = 1;j <= 9;j++){
cin >> a[i][j];
int x = i, y = j, z = i / 3 * 3 + j / 3;
if (a[i][j] != 0)
v[x][a[i][j]] = g[y][a[i][j]] = h[z][a[i][j]] = 1;
}
dfs(1);
return 0;
}