-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1434 [SHOI2002]滑雪.cpp
68 lines (64 loc) · 1.31 KB
/
P1434 [SHOI2002]滑雪.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
using namespace std;
const int maxR = 101;
const int maxC = 101;
int rows, cols;
//x为列col,y为行row
//所有数组都按照y,x读取
int map[maxR][maxC], f[maxR][maxC];
void dfs(int x, int y, int step) {
/*Update current step*/
//cout<<f[y][x]<<endl;
if(f[y][x]<step)
f[y][x] = step;
else if(step!=1)
return;
/*Search for next step that is avaliable*/
step++;
if(//Right
x+1<cols
&&
map[y][x+1] > map[y][x]
)
dfs(x+1, y, step);
if(//Down
y+1<rows
&&
map[y+1][x] > map[y][x]
)
dfs(x, y+1, step);
if(//Left
x-1>=0
&&
map[y][x-1] > map[y][x]
)
dfs(x-1, y, step);
if(//Up
y-1>=0
&&
map[y-1][x] > map[y][x]
)
dfs(x, y-1, step);
}
int main () {
cin>>rows>>cols;
for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++) {
cin>>map[i][j];
f[i][j] = 1;
}
}
for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++) {
dfs(j, i, 1);//x为列col,y为行row
}
}
int ans = 0;
for(int i=0; i<rows; i++) {
for(int j=0; j<cols; j++) {
ans = max(ans, f[i][j]);
}
}
cout<<ans<<endl;
return 0;
}