Implement the functionality to count bear configurations within a given land grid represented as a 2D array. The grid contains different symbols that represent various elements on the land. Your goal is to determine the number of valid configurations of bears based on specific rules defined in the logic.
Function Signature:
python
def count_bear_configurations(N, land):
Input Requirements:
N (int): An integer representing the dimensions of the land grid (N x N). The value of N will be in the range of 1 to 100.
land (List[List[str]]): A 2D list of strings, where each string can be one of the following:
'?' (unknown space where bears can be placed),
'B' (a bear),
'P' (a polar bear),
'G' (a grass that is not allowed to be adjacent to bears),
'.' (an empty space).
The total number of characters in the land grid will be exactly N*N.
Output Requirements:
Returns an integer representing the number of valid bear configurations modulo (10^9 + 7). The function handles edge cases based on the following rules:
If a configuration includes grass 'G', it is invalid and should return 0.
If a configuration contains both a bear 'B' and a polar bear 'P', it is also invalid and should return 0.
If there are only unknown spaces '?' in a connection, it can support 3 configurations.
If there are only empty spaces '.', it can support 2 configurations.
Any combination of 'B', 'P', and known spaces should be properly evaluated to return the correct configuration count.
Implementation Instructions:
Create a file named /app/solution.py.
Ensure that your implementation adheres to the provided function signature and correctly handles the input and output as specified above.
Include necessary comments to explain key parts of your logic and any helper functions you may create.
Your implementation should effectively count all the valid configurations based on the described rules and return the result as per the requirements.