python beat 97.25% easy understanding
\nclass Solution(object):\n    def numSubmatrixSumTarget(self, matrix, target):\n        m = len(matrix[0])\n        n = len(matrix)\n        res = 0\n        \
```\nclass Solution(object):\n    def numSubmatrixSumTarget(self, matrix, target):\n        m = len(matrix[0])\n        n = len(matrix)\n        res = 0\n        \n        prefix = [[0] * m for _ in range(n)]\n        \n        \n        for i in range(n):\n            for j in range(m):\n                if i == 0:\n                    prefix[i][j] = matrix[i][j]\n                else:\n                    prefix[i][j] = matrix[i][j] + prefix[i-1][j]\n        \n        for i in range(n):\n            for j in range(i, n):\n                d = {0:1}\n                cur = 0\n                for k in range(m):\n                    if i == 0:\n                        cur += prefix[j][k]\n                    else:\n                        cur += prefix[j][k] - prefix[i-1][k]\n                \n                    if cur - target in d:\n                        res += d[cur-target]\n\n                    if cur in d:\n                        d[cur] += 1\n                    else:\n                        d[cur] = 1\n        return res\n```
[]