C++ || DP || simple solution
\n/*\nLet the matrix be\n1 1\n1 1\nThere are 5 squares in total 4 of side 1 and 1 of side 2\nLogic I have used: \nif the current cell(i,j) is not 0, check for t
```\n/*\nLet the matrix be\n1 1\n1 1\nThere are 5 squares in total 4 of side 1 and 1 of side 2\nLogic I have used: \nif the current cell(i,j) is not 0, check for the min element in the left, right, diagonal element and add it to the value of current cell\nelse leave it as it is as there is no edge\n\nAfter applying this logic matrix becomes\n1 1\n1 2\nsumof all the elements in the matrix results in the total number of squares\n*/\nint countSquares(vector<vector<int>>& matrix) {\n\tint m=matrix.size(),n=matrix[0].size();\n\tfor(int i=1;i<m;i++){\n\t\tfor(int j=1;j<n;j++){\n\t\t\tif(matrix[i][j]!=0) matrix[i][j]+=min({matrix[i-1][j],matrix[i][j-1],matrix[i-1][j-1]});\n\t\t}\n\t}\n\tint cnt=0;\n\tfor(int i=0;i<m;i++){\n\t\tfor(int j=0;j<n;j++) cnt+=matrix[i][j];\n\t}\n\treturn cnt;\n}\n```\n**Please upvote:)**
['Dynamic Programming', 'C']