private int dfs(int[][] list, boolean[] visited, int cur, int remain) {
        if (remain == 0) return 1;
        int cnt = 0;
        visited[cur] = true;
        for (int i = 1; i <= 9; ++i) {
            int jump = list[cur][i];
            if (!visited[i] && (jump == 0 || visited[jump])) {
                cnt += dfs(list, visited, i, remain - 1);
            }
        }
        visited[cur] = false;
        return cnt;
    }