bool vis[3][10][10];
bool SetNum(int k,int i,int j)
{
k-='0';
if(vis[0][i][k]||vis[1][j][k]||vis[2][i/3*3+j/3][k])return false;
else{
vis[0][i][k] = true;
vis[1][j][k] = true;
vis[2][i/3*3+j/3][k] = true;
}
return true;
}
void DelNum(int k,int i,int j)
{
k-='0';
vis[0][i][k] = false;
vis[1][j][k] = false;
vis[2][i/3*3+ j/3][k] = false;
}
bool dfs(char** mp,int i ,int j)
{
if(j>=9){j-=9;i++;}
if(i>=9)return true;
if(mp[i][j] != '.')return dfs(mp,i,j+1);
for(int k = '1'; k <= '9' ; k ++)
{
mp[i][j]=k;
if(!SetNum(k,i,j)){
mp[i][j]='.';
continue;
}
if(dfs(mp,i,j+1))return true;
DelNum(k,i,j);
mp[i][j]='.';
}
return false;
}
void solveSudoku(char** board, int boardRowSize, int boardColSize) {
memset(vis,0,sizeof(vis));
for(int i = 0 ; i < 9 ; i ++){
for(int j = 0 ; j < 9 ; j ++)
{
if(board[i][j] != '.')SetNum(board[i][j],i,j);
}
}
dfs(board,0,0);
}