xQAQyn @ 2019-04-26 20:11:21
1、9两个点WA,2TLE
#include<bits/stdc++.h>
using namespace std;
int n,m;
int h[105][105];
int maxn = -1;
int next[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
struct Point
{
int x,y;
int v;
};
bool cmp(Point a,Point b)
{
return a.v > b.v;
}
void dfs(int x,int y,int step)
{
bool flag = false;
for(int i = 0;i < 4;i++)
{
int nx = x + next[i][0],ny = y + next[i][1];
if(nx > 0 && nx <= n && ny > 0 && ny <= m)
if(h[nx][ny] < h[x][y])
{
flag = true;
dfs(nx,ny,step+1);
}
}
if(!flag)
maxn = max(maxn,step);
}
int main()
{
Point k[10005];
int topk = 0;
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
{
scanf("%d",&h[i][j]);
Point kkk;
kkk.v = h[i][j];
kkk.x = i;
kkk.y = j;
k[topk++] = kkk;
}
sort(k,k + topk,cmp);
for(int i = 0;i < topk;i++)
{
if(maxn >= n - i)
break;
dfs(k[i].x,k[i].y,1);
}
cout<<maxn;
return 0;
}
by Tsumi @ 2019-04-26 20:17:36
建议打边界
by aminoas @ 2019-04-26 20:25:30
这个标题怎么和这个差不多...
好吧窝珂能是抓错重点了
by xQAQyn @ 2019-04-28 06:06:09
@坏掉了 ???怎么打边界
by Tsumi @ 2019-04-30 18:29:51
从0到n-1,0和n-1标记一下不能走,实际上差不多...