Chessboard Region Attacker - Problem
Given an N×N chessboard and K bishops, place all K bishops on the board such that no two bishops attack each other diagonally.
Two bishops attack each other if they are on the same diagonal (either main diagonal or anti-diagonal). Your task is to count the total number of valid arrangements where all K bishops can be placed without attacking each other.
Note: Bishops move diagonally any number of squares. A bishop at position (i, j) attacks all positions (i+x, j+x), (i+x, j-x), (i-x, j+x), and (i-x, j-x) where the resulting position is within the board bounds.
Input & Output
Example 1 — Small Board
$
Input:
n = 3, k = 2
›
Output:
26
💡 Note:
On a 3×3 board, we can place 2 non-attacking bishops in 26 different ways. Bishops placed on different colored squares never attack each other.
Example 2 — Single Bishop
$
Input:
n = 4, k = 1
›
Output:
16
💡 Note:
With only 1 bishop on a 4×4 board, we can place it on any of the 16 squares, so there are 16 valid arrangements.
Example 3 — Impossible Case
$
Input:
n = 2, k = 5
›
Output:
0
💡 Note:
On a 2×2 board, we can place at most 2 bishops (one on each color). Placing 5 bishops is impossible.
Constraints
- 1 ≤ n ≤ 10
- 0 ≤ k ≤ n²
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code