Functionality Implementation:
You are required to implement the function count_bear_configurations(N, land) which counts the number of valid configurations of bear placements on a square grid (land) based on specific rules related to bear types and their interactions.
Input Requirements:
The function takes two parameters:
N (Integer): The size of the grid, where the grid is N x N.
land (List of Lists): A 2D list representing the grid where:
Each element can be:
'B': a bear,
'P': a penguin,
'G': grass,
'?': an empty space that can be filled with either bear or penguin,
'.': an empty space that cannot be filled (not relevant to bears).
Output Requirements:
The function should return a single integer, representing the number of valid bear configurations modulo (10^9 + 7).
Rules for Valid Configurations:
If a connected component has only one '?' cell, it can be filled in three ways.
If the component contains 'G', then the configuration is invalid (returns 0).
If both 'B' and 'P' are present in the same component, it’s invalid (returns 0).
If the component contains either 'B' or 'P' but not both, it has 1 valid way.
If the component contains none of these characters, then it has 2 valid ways of filling '?'.
Implementation Instructions:
Implement the above functionality in a Python file named /app/solution.py.
Ensure that the implementation adheres to the input and output specifications.
Engage recursive exploration for connected components in the grid and apply the counting rules accordingly.
The solution should be scalable for different values of N while adhering to the constraints outlined.