N-queens problem objective function I have read about the N-queens problem and I don't understand the following objective function:

$O(board)=N^2/2-L$

$N$ ... number of queens
$L$ ... number of pairs of queens that attack each other

Why they use $N^2/2$? They wrote that it is the number of pairs of queens but I don't understand that can someone maybe explain it to me maybe with visualization
The objective function you describe satisfies two properties:


It is maximized at a solution.
It is non-negative.


One can think of many other functions satisfying these two properties, for example $\binom{N}{2} - L + C$ for every $C \geq 0$. The exact choice is not so important – indeed, they chose $N^2/2$ whereas they could have chosen $\binom{N}{2} = N(N-1)/2$.