Skip to content

Commit

Permalink
Dp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashish-kumar7 committed May 12, 2020
1 parent 549ba4b commit 39a4e7e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions DP/Largest square formed in a matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int A[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>A[i][j];
}
}
int B[n+1][m+1];
int max=INT_MIN;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0 || j==0){
B[i][j]=0;
}
else if(A[i-1][j-1]==0){
B[i][j]=0;
}
else if(A[i-1][j-1]==1){
B[i][j]=min( B[i-1][j-1] , min( B[i-1][j], B[i][j-1]) ) +1;
}

if(max<B[i][j]){
max=B[i][j];
}
}
}
cout<<max<<endl;
}
return 0;
}

0 comments on commit 39a4e7e

Please sign in to comment.