尝试使用回溯法解数独,但运行不出结果,请问代码错在哪里?

#include<iostream>
#include<vector>
using namespace std;
class Solution {
private:
    bool finished = false;
    void dfs(vector<vector<int>>& board, int n)
    {
        if (n >= 81)
        {
            finished = true;
            return;
        }
        int x = n % 9;
        int y = n / 9;
        if (board[y][x] != 0)
        {
            dfs(board, n + 1);
        }
        else
        {
            for (int i = 1; i <= 9; i++)
            {
                if (!isvaild(board, i, n)) continue;
                board[y][x] = i;
                dfs(board, n + 1);
                if (finished == true) return;
                board[y][x] = 0;

            }
        }
        return;
    }
    bool isvaild(vector<vector<int>>& board, int ch, int n)
    {
        int x = n % 9;
        int y = n / 9;
        for (int i = 0; i < 9; i++)
        {
            if (board[i][x] == ch)  return false;
            if (board[y][i] == ch)  return false;
        }
        int x1 = (x / 3) * 3;
        int y1 = (x / 3) * 3;
        for (int j = y1; j < y1 + 3; j++)
        {
            for (int i = x1; i < x1 + 3; i++)
            {
                if (board[j][i] == ch)  return false;
            }
        }
        
        return true;
    }
public:
    void solveSudoku(vector<vector<int>>& board) {
        dfs(board, 0);
        return;
    }
};

int main()
{
    vector<vector<int>>vet{ {5,3,0,0,7,0,0,0,0},
                            {6,0,0,1,9,5,0,0,0},
                            {0,9,8,0,0,0,0,6,0},
                            {8,0,0,0,6,0,0,0,3},
                            {4,0,0,8,0,3,0,0,1},
                            {7,0,0,0,2,0,0,0,6},
                            {0,6,0,0,0,0,2,8,0},
                            {0,0,0,4,1,9,0,0,5}, 
                            {0,0,0,0,8,0,0,7,9} };
    Solution sol;
    sol.solveSudoku(vet);
    for (int i = 0; i < 9; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            cout << vet[i][j] << ' ';
        }
        cout << endl;
    }
    return 0;
}

运行结果如下:

 

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。

​​​​因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。