Problema in c++
Am nevoi de rezolvarea punctului 9
Răspunsuri la întrebare
#include <bits/stdc++.h>
using namespace std;
ifstream fin("patrat.in");
ofstream fout("patrat.out");
int a[1001][1001],dp[1001][1001],n,i,j;
void Citire()
{
fin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
fin>>a[i][j];
}
int Min(int a,int b,int c)
{
if(a<=b&&a<=c) return a;
if(b<=a&&b<=c) return b;
return c;
}
void Dinamica()
{
int Max=0,lin=0,col=0;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(a[i][j]==0) dp[i][j]=0;
else dp[i][j]=1+Min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(dp[i][j]>Max)
{
Max=dp[i][j];
lin=i-Max+1;
col=j-Max+1;
}
fout<<Max<<" "<<lin<<" "<<col;
}
int main()
{
Citire();
Dinamica();
return 0;
}