human
Ways to place K bishops on an NÃ — N chessboard so that no two attack | returns the number of squares in diagonal i.
returns the number of ways to fill a n * n chessboard with k bishops so that no two bishops attack each other ..
return 0 if the number of valid places to be filled is less than the number of bishops.
dp table to store the values.
Setting the base conditions.
calculate the required number of ways.
stores the answer.
Driver code"
How can the above be solved in Python?
 ... What is a code to ways to place K bishops on an NÃ — N chessboard so that no two attack and the other steps required?
assistant
#Here is code to ways to place K bishops on an NÃ — N chessboard so that no two attack and the other steps required.
 def squares ( i ) :
	if ( ( i & 1 ) == 1 ) :
		return int ( i / 4 ) * 2 + 1
	else :
		return int ( ( i - 1 ) / 4 ) * 2 + 2
def bishop_placements ( n , k ) :
	if ( k > 2 * n - 1 ) :
		return 0
	dp = [ [ 0 for i in range ( k + 1 ) ] for i in range ( n * 2 ) ]
	for i in range ( n * 2 ) :
		dp [ i ] [ 0 ] = 1
	dp [ 1 ] [ 1 ] = 1
	for i in range ( 2 , n * 2 , 1 ) :
		for j in range ( 1 , k + 1 , 1 ) :
			dp [ i ] [ j ] = ( dp [ i - 2 ] [ j ] + dp [ i - 2 ] [ j - 1 ] * ( squares ( i ) - j + 1 ) )
	ans = 0
	for i in range ( 0 , k + 1 , 1 ) :
		ans += ( dp [ n * 2 - 1 ] [ i ] * dp [ n * 2 - 2 ] [ k - i ] )
	return ans
if __name__ == ' _ _ main _ _ ' :
	n = 2
	k = 2
	ans = bishop_placements ( n , k )
	print ( ans )