#K34402. N Queens Puzzle

    ID: 25301 Type: Default 1000ms 256MiB

N Queens Puzzle

N Queens Puzzle

The task is to determine the number of distinct ways to place N queens on an N x N chessboard so that no two queens can attack each other. In other words, no two queens are allowed to share the same row, column, or diagonal. This is a classical problem often solved using backtracking.

The queen placement must satisfy the following conditions for a valid configuration:

  • No two queens in the same row.
  • No two queens in the same column.
  • No two queens in the same diagonal.

Mathematically, if we denote a valid arrangement as one of the solutions, the goal is to count the total number of solutions S(N) where
$$ S(N)=\text{Number of valid configurations of N queens on an } N \times N \text{ board.} $$

inputFormat

The input consists of a single integer N which represents the size of the chessboard (N x N) and the number of queens to place.

Constraints: 1 ≤ N ≤ 15 (typical range for the problem).

outputFormat

Output a single integer representing the number of distinct solutions for placing N queens on an N x N chessboard such that no two queens attack each other.

## sample
1
1