-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathsum_of_submatrix.cpp
More file actions
45 lines (44 loc) · 848 Bytes
/
Copy pathsum_of_submatrix.cpp
File metadata and controls
45 lines (44 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<iostream>
using namespace std;
int maxsumSubmatrix(int *arr[], int n, int m)
{
for(int i=n-1;i>=0;i--) //Column wise Sum
{
for(int j=m-2;j>=0;j--)
{
arr[i][j]+= arr[i][j+1];
}
}
for(int i=m-1;i>=0;i--) //Row Wise Sum
{
for(int j=n-2;j>=0;j--)
{
arr[j][i]+= arr[j+1][i];
}
}
int result= INT_MIN;
for(int i=0;i<n;i++)
{
for(int i=0;i<m;i++)
{
result= max(result, arr[i][j]);
}
}
return result;
}
int main(int argc, char const *argv[])
{
int m,n;cin>>m>>n;
int **arr= new int*[n];
for(int i=0;i<n;i++)
{
arr[i]= new int[m];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout>>arr[i][j];
}
}
}