-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaxSubSquareMatrix.CPP
More file actions
44 lines (35 loc) · 894 Bytes
/
maxSubSquareMatrix.CPP
File metadata and controls
44 lines (35 loc) · 894 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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void printT(vector<vector<int>> T){
for(auto x:T){
for(auto y:x)
cout << y <<" ";
cout << endl;
}
}
int subsquareMatrix(vector<vector<int>> &A){
vector<vector<int>> T(A.size()+1,vector<int>(A[0].size()+1,0));
for(int i=1; i<=A.size();++i){
for(int j=1; j<=A[0].size(); ++j){
if(A[i-1][j-1]){
T[i][j] = A[i-1][j-1] + min(T[i-1][j], min(T[i-1][j-1],T[i][j-1]));
}
}
}
printT(T);
int max = 0;
for(auto x: T){
int y = *max_element(x.begin(),x.end());
max = (y>max)?y:max;
}
return max;
}
int main()
{
vector<vector<int>> A = {{0,0,1,1,1},{1,0,1,1,1},{0,1,1,1,1},{1,0,1,1,1}};
cout << subsquareMatrix(A) << endl;
return 0;
}