1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<cstdlib>
5 using namespace std;
6 int map[10][10];
7 int vis[10][10];
8 int hang[10][10];
9 int lie[10][10];
10 int group[10][10]=
11 {
12 0,0,0,0,0,0,0,0,0,0,
13 0,1,1,1,2,2,2,3,3,3,
14 0,1,1,1,2,2,2,3,3,3,
15 0,1,1,1,2,2,2,3,3,3,
16 0,4,4,4,5,5,5,6,6,6,
17 0,4,4,4,5,5,5,6,6,6,
18 0,4,4,4,5,5,5,6,6,6,
19 0,7,7,7,8,8,8,9,9,9,
20 0,7,7,7,8,8,8,9,9,9,
21 0,7,7,7,8,8,8,9,9,9,
22 };
23 int group_vis[10][10];
24 void dfs(int x,int y)
25 {
26 if(x==10)
27 {
28 for(int i=1;i<=9;i++)
29 {
30 for(int j=1;j<=9;j++)
31 printf("%d ",map[i][j]);
32 printf("\n");
33 }
34 exit(0);}
35
36 int wx=x;int wy=y+1;
37 if(wy==10)
38 {wy=1;
39 wx=x+1;}
40
41 if(map[x][y]!=0)dfs(wx,wy);
42 else
43 {
44 for(int j=1;j<=9;j++)
45 {
46 if(hang[x][j]==0&&lie[y][j]==0&&group_vis[group[x][y]][j]==0)
47 {
48 hang[x][j]=1;lie[y][j]=1;group_vis[group[x][y]][j]=1;
49 map[x][y]=j;
50 dfs(wx,wy);
51 map[x][y]=0;
52 hang[x][j]=0;lie[y][j]=0;group_vis[group[x][y]][j]=0;
53 }
54 }
55 }
56 }
57 int main()
58 {
59 for(int i=1;i<=9;i++)
60 for(int j=1;j<=9;j++)
61 {
62 scanf("%d",&map[i][j]);
63 if(map[i][j]!=0){hang[i][map[i][j]]=1;lie[j][map[i][j]]=1;group_vis[group[i][j]][map[i][j]]=1;}
64 }
65 dfs(1,1);
66 return 0;
67 }