dp
然而我们可以使用前缀和+暴搜,而且更好理解,同时复杂度约O(n2),能过
#include<bits/stdc++.h>
using namespace std;
int n,m,a[2505][2505],x[2505][2505],y[2505][2505],z[2505][2505],ans;
bool ed_1[2505][2505],ed_2[2505][2505];
int kan1(int i,int j){
int d=0;
while(a[i][j]&&(x[i][j-1]>=d)&&(y[i-1][j]>=d))i++,j++,d++;
return d;
}
int kan2(int i,int j){
int d=0;
while(a[i][j]&&(z[i][j+1]>=d)&&(y[i-1][j]>=d))i++,j--,d++;
return d;
}
int main() {
cin>>n>>m;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j],x[i][j]=(a[i][j]?0:x[i][j-1]+1);
for(int j=1;j<=m;j++)for(int i=1;i<=n;i++)y[i][j]=(a[i][j]?0:y[i-1][j]+1);
for(int i=1;i<=n;i++)for(int j=m;j>0;j--)z[i][j]=(a[i][j]?0:z[i][j+1]+1);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]&&!ed_1[i][j])ans=max(ans,kan1(i,j));
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]&&!ed_2[i][j])ans=max(ans,kan2(i,j));
cout<<ans;
}
标签:int,ed,++,while,&&,2505,P1736
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18452401