Simple Python solution
IntuitionImagine a robot that wants to collect the maximum coins while moving from the top-left to the bottom-right of a grid. Some cells have robbers that stea
# Intuition
Imagine a robot that wants to collect the maximum coins while moving from the top-left to the bottom-right of a grid. Some cells have robbers that steal coins, but the robot can neutralize up to two robbers during its journey. We need a way to track the robot's path and decide when to neutralize robbers to get the best outcome.

# Approach
1. Use a dynamic programming (DP) table where `dp[i][j][k]` represents the maximum coins collected when reaching cell `(i, j)` with `k` neutralizations used.
2. Start at the top-left corner, initializing the DP table based on whether the starting cell has a robber.
3. Fill the DP table by considering two possible moves to each cell: coming from the top or from the left.
   - If the current cell is positive, add its value to the previous best path.
   - If the cell is negative (a robber), decide whether to neutralize it (if neutralizations are left) or not.
4. At the end, look at the bottom-right corner of the grid and find the maximum coins collected with up to 2 neutralizations.

# Complexity
- Time complexity: $$O(m \times n \times 3)$$, where $$m$$ is the number of rows, $$n$$ is the number of columns, and we check up to 3 neutralizations for each cell.
- Space complexity: $$O(m \times n \times 3)$$, as we store the DP table with 3 states for each cell.


# Code
```python3 []
class Solution:
    def maximumAmount(self, coins: List[List[int]]) -> int:
        m, n = len(coins), len(coins[0])

        dp = [[[float('-inf')] * 3 for _ in range(n)] for _ in range(m)]
    
        for k in range(3):
            dp[0][0][k] = 0 if coins[0][0] < 0 and k > 0 else coins[0][0]
    
        for i in range(m):
            for j in range(n):
                for k in range(3):
                    if i == 0 and j == 0:
                        continue 
    
                    gain = coins[i][j]
    
                    if i > 0:
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + gain)
                        if k > 0 and gain < 0:
                            dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1])
    
                    if j > 0:
                        dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k] + gain)
                        if k > 0 and gain < 0:
                            dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1])
    
        return  max(dp[m - 1][n - 1])
       

```

As pointed out by [Jojo](https://leetcode.com/u/wxy0925/), the return statement could be updated to `dp[-1][-1][-1]` or `dp[m-1][n-1][2]`.
['Dynamic Programming', 'Python3']