E_tc @ 2019-05-08 19:42:05
为什么第一个点WA,第二个点TLE;
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int a[110][110];
int v[110][110];
int n,m,x,y;
int sum=1;
int maxn=-0x7fffffff;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dfs(int x,int y)
{
maxn=-0x7fffffff;
int fx,fy,flag=0;
for(int i=0;i<=3;i++)
{
int xx=a[x+dx[i]][y+dy[i]];
if(xx < a[x][y] && xx > maxn && x+dx[i] >=1 && x+dx[i]<=n && y+dy[i] >= 1 && y+dy[i]<=m && !v[x+dx[i]][y+dy[i]])
{
flag=1;
maxn=xx;
fx=x+dx[i];
fy=y+dy[i];
}
}
if(flag)
{
sum++;
v[fx][fy]=1;
dfs(fx,fy);
}
else
return sum;
}
int main()
{
int ans=-1;
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
sum=1;
memset(v,0,sizeof(v));
ans=max(ans,dfs(i,j));
}
cout<<ans;
return 0;
}
by CreeperLordVader @ 2019-05-08 19:45:22
不加记忆化肯定TLE啊
by E_tc @ 2019-05-08 19:47:12
谢谢大佬,那第一个点WA是什么鬼? @CreeperLordVader
by aminoas @ 2019-05-08 19:49:41
鬼不是两栖动物啊喂
by 山水一程_ @ 2019-05-08 19:50:17
@E_tc 某人:我再发讨论我就chi shi!
by 朱子瑜 @ 2019-05-08 20:20:43
_ ~~**he