[Python 3]Count Square Submatrices w/ All ones.
Logic: Create new dp matrix. To fill this matrix follow follwing rules:\n\n1. If matrix[i][j] == 0: then fill it in dp as it is. i.e. dp[i-1][j-1] = 0\n2.  If m
**Logic:** Create new dp matrix. To fill this matrix follow follwing rules:\n\n1. If matrix[i][j] == 0: then fill it in dp as it is. i.e. dp[i-1][j-1] = 0\n2.  If matrix[i][j] == 1: then take minimum of left, diagonally up, up elements and add 1 to it. The result will give the size of square till now. (if 2, then 2x2 matrix is made till now).\n3.  return number of squares by counting all the elements.\n\n\n```\nclass Solution:\n    def countSquares(self, matrix: List[List[int]]) -> int:\n        \n        n = len(matrix[0])  # col\n        m = len(matrix)     # rows\n        \n        dp = [[0]*(n+1) for i in range(m+1)]\n        \n        for i in range(1,m+1):\n            for j in range(1,n+1):\n                if matrix[i-1][j-1] == 0:\n                    dp[i][j]=0\n                else:\n                    dp[i][j] = min(dp[i-1][j-1], dp[i-1][j], dp[i][j-1])+1\n                    \n        sum1=0\n        \n        for i in range(m+1):\n            for j in range(n+1):\n                sum1+=dp[i][j]\n                \n        return sum1\n```
['Dynamic Programming', 'Python']