CherYou @ 2017-05-07 16:42:47
#include<iostream>
#include<cstdio>
#define MAXN 2505
using namespace std;
int n,m,ans=0,ans1=0;
int map[MAXN][MAXN];
void dfs1(int x,int y)
{
ans++;
if(map[x+1][y+1]&&x+1>0&&x+1<=n&&y+1>0&&y+1<=m) dfs1(x+1,y+1);
}
void dfs2(int x,int y)
{
ans1++;
if(map[x+1][y-1]&&x+1>0&&x+1<=n&&y-1>0&&y-1<=m) dfs2(x+1,y-1);
}
int main()
{
int ans2=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&map[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(map[i][j]==1)
{
ans=0;ans1=0;
dfs1(i,j);dfs2(i,j);
ans2=max(ans2,max(ans,ans1));
}
cout<<ans2;
}
by CherYou @ 2017-05-07 21:05:04
发现完全没看到周围要是“0”