k bishops on an nXn chessboard We have previously solved the “N Queens Problem
ID: 3535274 • Letter: K
Question
k bishops on an nXn chessboard
We have previously solved the “N Queens Problemâ€, where, for a given n, we calculated the
number of ways to place n queens on an nXn board. This problem concerns “bishops†on the
chessboard.
What is a bishop?
A bishop is a chess piece that controls all the squares on the two diagonals that it can reach.
Note that a bishop may be either on a white square or a black square.
The problem
Write a program that inputs two integers n and k, where n>=k. Your program should calculate
the number of different ways that k bishops could be placed on an nXn chessboard.
Structure your program using the backtracking scheme that we have used for the eight queens
problem. What needs to be modified is the “OK†function.
Input
Your main program should loop asking the user for values of n and k.
Output
Each time through the loop, output n, k and the number of configurations.
Program Termination
The program will terminate if the user enters a value of -1 for n.
Explanation / Answer
http://ideone.com/YeHOad
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.