貪心高性能神經(jīng)網(wǎng)絡(luò)與AI芯片應(yīng)用研修
? ? ?System.out.println(new SolveNQueens().solveNQueens(8).size());
? ?}
? ?public List<List<String>> solveNQueens(int n) {
? ? ? ?return solveNQueens(n, n);
? ?}
? ?// 解決N皇后問題的第x層
? ?// 在解決第x層之前,假設(shè)第x-1層已經(jīng)得到的解決
? ?public List<List<String>> solveNQueens(int n, int x) {
? ? ? ?if (x == 1) {
? ? ? ? ? ?// 正在棋盤的第1行擺放皇后
? ? ? ? ? ?List<List<String>> solutionOfFirstRow = new ArrayList<>();
? ? ? ? ? ?for (int i = 1; i <= n; i++) {
? ? ? ? ? ? ? ?solutionOfFirstRow.add(Collections.singletonList(queenAt(i, n)));
? ? ? ? ? ?}
標(biāo)簽: