-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1004.c.k
46 lines (38 loc) · 1.3 KB
/
P1004.c.k
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
#include <stdio.h>
#include <string.h>
#define _(data_array, r, c) *(data_array + (r) * c_bound + (c))
int r_bound, c_bound, *data, *traveled
int dfs(int r, int c):
int *ptr = &_(traveled, r, c), max = 0, temp
if *ptr:
return *ptr
if r > 0 && _(data, r - 1, c) < _(data, r, c):
if (temp = dfs(r - 1, c)) > max:
max = temp
if r < r_bound - 1 && _(data, r + 1, c) < _(data, r, c):
if (temp = dfs(r + 1, c)) > max:
max = temp
if c > 0 && _(data, r, c - 1) < _(data, r, c):
if (temp = dfs(r, c - 1)) > max:
max = temp
if c < c_bound - 1 && _(data, r, c + 1) < _(data, r, c):
if (temp = dfs(r, c + 1)) > max:
max = temp
return *ptr = ++max
int main(void):
scanf("%d %d", &r_bound, &c_bound)
int data_array[r_bound][c_bound]
int traveled_array[r_bound][c_bound]
data = (int *)data_array
traveled = (int *)traveled_array
memset(traveled, 0, sizeof(traveled_array))
for int r = 0; r < r_bound; r++:
for int c = 0; c < c_bound; c++:
scanf("%d", &_(data, r, c))
int max = 0
for int r = 0; r < r_bound; r++:
for int c = 0; c < c_bound; c++:
if max < dfs(r, c):
max = dfs(r, c)
printf("%d\n", max)
return 0