-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10285.cpp
More file actions
58 lines (53 loc) · 953 Bytes
/
10285.cpp
File metadata and controls
58 lines (53 loc) · 953 Bytes
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
#include<stdio.h>
#define SZ 105
int R, C;
int res;
char str[SZ];
int grid[SZ][SZ];
int seen[SZ][SZ], cs=1;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
void input(){
int i, j;
for(i=1; i<=R; i++)
for(j=1; j<=C; j++)
scanf("%d", &grid[i][j]);
}
void BtKt(int r, int c, int step){
int i, tr, tc;
for(i=0; i<4; i++){
tr = r + dr[i];
tc = c + dc[i];
if( tr<1 || tr>R || tc<1 || tc>C )continue;
if( grid[tr][tc] >= grid[r][c] ) continue;
if( seen[tr][tc] == cs ) continue;
seen[tr][tc] = cs;
if( step+1>res )
res = step+1;
BtKt(tr, tc, step+1);
seen[tr][tc] = 0;
}
}
int solution(){
int i, j, ret=-1;
for(i=1; i<=R; i++){
for(j=1; j<=C; j++){
res = 0;
BtKt(i, j, 1);
if( res>ret )
ret = res;
}
}
return ret;
}
int main(){
freopen("10285.txt", "r", stdin);
int t;
scanf("%d", &t);
while(t--){
scanf("%s%d%d", str, &R, &C);
input();
printf("%s: %d\n", str, solution());
}
return 0;
}