just a variant
Code\n\nclass Solution {\n    fun numSubmatrixSumTarget(matrix: Array<IntArray>, target: Int): Int {\n        val n = matrix.lastIndex\n        val m = matrix.f
# Code\n```\nclass Solution {\n    fun numSubmatrixSumTarget(matrix: Array<IntArray>, target: Int): Int {\n        val n = matrix.lastIndex\n        val m = matrix.first().lastIndex\n        val dp = Array(101) { IntArray(101) }.also { it[0][0] = matrix[0][0] }\n\n        (1..n).forEach { dp[it][0] = matrix[it][0] + dp[it - 1][0] }\n        (1..m).forEach { dp[0][it] = matrix[0][it] + dp[0][it - 1] }\n        (1..n).forEach { i ->\n            (1..m).forEach { j ->\n                dp[i][j] = matrix[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] } }\n\n        return (0..n).sumOf { i ->\n                    (0..m).sumOf { j ->\n                        (i..n).sumOf { l ->\n                            (j..m).count { k ->\n                                target == dp[l][k] - (if (i > 0) dp[i - 1][k] else 0) - (if (j > 0) dp[l][j - 1] else 0) +\n                                                     (if (i > 0 && j > 0) dp[i - 1][j - 1] else 0) } } } }\n    }\n}\n```
['Kotlin']