Segmentree @ 2019-07-30 21:17:43
这道题调了好久。。。
/*Coded By Lxhao*/
/*Full Of Stars*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#define re register
#define r(x) x=read()
#define c getchar()
#define ll long long
inline int read()
{
int w=1,s=0;
char ch=c;
while(ch>'9'||ch<'0'){if(ch=='-')w=-1;ch=c;}
while(ch>='0'&&ch<='9')s=(s<<1)+(s<<3)+ch-'0',ch=c;
return s*w;
}
#define map a
int maxn=-1,maxx;
int map[101][101],n,m;
int ans[101][101],dx[5]={23333,0,0,1,-1},dy[5]={23333,1,-1,0,0};
inline int dfs(int x,int y)
{
if(ans[x][y])return ans[x][y];
maxx=1;
for(re int i=1;i<=4;++i)
{
int nowx=x+dx[i],nowy=y+dy[i];
if(nowx>=1&&nowx<=n&&nowy>=1&&nowy<=m&&map[nowx][nowy]>map[x][y])
maxx=max(maxx,dfs(nowx,nowy)+1);
}
ans[x][y]=maxx;
return maxx;
}
int main()
{
r(n),r(m);
for(re int i=1;i<=n;++i)
for(re int j=1;j<=m;++j)
r(map[i][j]);
for(re int i=1;i<=n;++i)
for(re int j=1;j<=m;++j)
{
maxx=dfs(i,j);
ans[i][j]=maxx;
maxn=max(maxn,ans[i][j]);
}
printf("%d",maxn);
}
by Segmentree @ 2019-07-30 23:29:07
哦我查到现在终于查出来了,dfs里面的maxx变量只能开局部变量,不然会传递给主函数里面的maxx