Maximum non-attacking Knights that can be placed on an N*M Chessboard
Given an N*M chessboard. The task is to find the maximum number of knights that can be placed on the given chessboard such that no knight attack some other knight.
Input: N = 1, M = 4
Place a knight on every cell of the chessboard.
Input: N = 4, M = 5
Approach: As we know that a knight can attack in two ways. Here are the places which he can attack.
Here, in the picture, the knight is on white color and attacks only the black color. Thus. we concluded that a knight can attack only on a different color.
We can take help of this fact and use it for our purpose. Now as we know knight attacks on different color so we can keep all knights on the same color i.e. all on white or all on black. Thus making the highest number of knights which can be placed.
To find the number of black or white, it is simply half of the total blocks on board.
Total Blocks = n * m
Blocks of the same color = (n * m) / 2