C++ modified Kadene's algorithm O(N*N*M + M)
\nclass Solution {\npublic:\n    \n    //number of subarrays having sum equals to k\n    int go(vector<int> &nums, int k)\n    {\n        unordered_map<int,int>
```\nclass Solution {\npublic:\n    \n    //number of subarrays having sum equals to k\n    int go(vector<int> &nums, int k)\n    {\n        unordered_map<int,int> m;\n        \n        int sum=0,ans=0;\n        \n        m[0] = 1;\n        \n        for(int num:nums)\n        {\n            sum += num;\n            int target = sum - k;\n            if(m.count(target))\n                ans += m[target];\n            \n            m[sum]++;\n        }\n        return ans;\n    } \n    //----------------------------------------------------------------\n    int numSubmatrixSumTarget(vector<vector<int>>& matrix, int target) {\n        \n        int n = matrix.size(), m = matrix[0].size();\n        \n        int res = 0;\n       \n        for(int i=0; i<n; i++)\n        {\n            vector<int> temp(m,0);         \n            for(int j=i; j<n; j++)\n            {\n                for(int k=0; k<m; k++)\n                    temp[k] += matrix[j][k];\n                \n                //all sub-matrices between row i and j.\n                res += go(temp, target);\n            }       \n        }\n        return res;   \n    }\n};\n```
['Dynamic Programming']