-
Notifications
You must be signed in to change notification settings - Fork 0
/
p1434.cpp
45 lines (44 loc) · 990 Bytes
/
p1434.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
int a,b,ip[110][110],lst[110][110],dx[4]={0,0,-1,1},dy[4]={-1,1,0,0};
void opt(int x,int y)
{
if(lst[x][y])
return;
lst[x][y] = 1;
for (int i = 0; i < 4;++i)
{
int nx = x + dx[i], ny = y + dy[i];
if(ip[x][y]>ip[nx][ny]&&1<=nx&&nx<=a&&1<=ny&&ny<=b)
{
opt(nx, ny);
lst[x][y] = max(lst[x][y], lst[nx][ny]+1);
}
}
return;
}
int main()
{
scanf("%d%d", &a, &b);
for (int i = 1; i <= a;i++)
{
for (int j = 1; j <= b;++j)
{
scanf("%d", &ip[i][j]);
}
}
memset(lst, 0, sizeof(lst));
int ans = 1;
for (int i = 1; i <= a;++i)
{
for (int j = 1; j <= b;++j)
opt(i, j);
}
for (int i = 1; i <= a;++i)
{
for (int j = 1; j <= b;++j)
ans = max(ans, lst[i][j]);
}
printf("%d\n", ans);
return 0;
}