-
Notifications
You must be signed in to change notification settings - Fork 126
/
Copy pathUVa10285.cc
51 lines (46 loc) · 1.27 KB
/
UVa10285.cc
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
// UVa10285 Longest Run on a Snowboard
// 陈锋
#include<cassert>
#include<cstdio>
#include<functional>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
using namespace std;
int readint() { int x; scanf("%d", &x); return x;}
const int MAXH = 100 + 5;
int R, C, M[MAXH][MAXH], D[MAXH][MAXH];
int dp(int i, int j) {
int& ans = D[i][j];
if(ans != -1) return ans;
ans = 1;
int h = M[i][j];
if(i > 0 && M[i-1][j] < h) ans = max(ans, 1+dp(i-1,j));
if(j > 0 && M[i][j-1] < h) ans = max(ans, 1+dp(i,j-1));
if(i+1 < R && M[i+1][j] < h) ans = max(ans, 1+dp(i+1,j));
if(j+1 < C && M[i][j+1] < h) ans = max(ans, 1+dp(i,j+1));
return ans;
}
int main()
{
int N = readint();
char name[64];
while(N--) {
scanf("%s", name);
R = readint(), C = readint();
for(int i = 0; i < R; i++)
for(int j = 0; j < C; j++)
M[i][j] = readint();
memset(D, -1, sizeof(D));
int ans = 0;
for(int i = 0; i < R; i++)
for(int j = 0; j < C; j++)
ans = max(ans, dp(i,j));
printf("%s: %d\n", name, ans);
}
return 0;
}
// 14804646 10285 Longest Run on a Snowboard Accepted C++ 0.029 2015-01-15 04:39:38