Easy prefix Sum approach
\nclass Solution {\npublic:\n    int dp[101][101];\n    int n,m;\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        n=matrix.siz
```\nclass Solution {\npublic:\n    int dp[101][101];\n    int n,m;\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        n=matrix.size(),m=matrix[0].size();\n        fun(matrix);\n        int ans=0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n               int si=i,sj=j;\n               \n                for(int p=si;p<n;p++){\n                    for(int q=sj;q<m;q++){\n                     \n                        if(p==si && q==sj){\n                           \n                            ans+=(target==matrix[p][q])?1:0;\n                        }else{\n                          \n                             ans+=(target==getans(si,sj,p,q))?1:0;\n                        }\n                    }\n                }\n               \n            }\n        }\n        return ans;\n    }\n   void fun(vector<vector<int>>& matrix){\n        dp[0][0]=matrix[0][0];      // Getting the sum of matrix from index(0,0) for every (i,j);\n        for(int i=1;i<m;i++){\n            dp[0][i]=(dp[0][i-1]+matrix[0][i]);\n        }\n        for(int i=1;i<n;i++){\n            dp[i][0]=(dp[i-1][0]+matrix[i][0]);\n        }\n        for(int i=1;i<n;i++){\n            for(int j=1;j<m;j++){\n                dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+matrix[i][j];\n            }\n        }\n       \n    }\n    \n  int getans(int si,int sj,int ei,int ej){\n        if(si==0 && sj==0){\n            return dp[ei][ej];\n        }else if(si==0 && sj!=0){\n            return dp[ei][ej]-dp[ei][sj-1];\n        }else if(si!=0 && sj==0){\n            return dp[ei][ej]-dp[si-1][ej];\n        }else{\n             return dp[ei][ej]-dp[ei][sj-1]-dp[si-1][ej]+dp[si-1][sj-1];\n        }\n     \n    }\n};\n```
['Matrix', 'Prefix Sum']