-
Notifications
You must be signed in to change notification settings - Fork 0
/
COJ-1026.cpp
52 lines (47 loc) · 971 Bytes
/
COJ-1026.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
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#define MAX 101
#define FOR(i,n) for(__typeof (n) i=0;i<n;i++)
using namespace std;
int R,C;
int dp[101][101];
int arr[101][101];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string s;
int bfs(int i, int j)
{ if(dp[i][j]!=-1) return dp[i][j];
int res = 0;
for(int u = 0; u < 4; u++){
int x = i + dx[u];
int y = j + dy[u];
if(x>=0 && y>=0 && x<R && y<C && arr[x][y] < arr[i][j]){
res = max(res, 1 + bfs(x,y));
}
}
return dp[i][j] = res;
}
int main()
{ int T;
cin>>T;
while(T--){
cin>>s>>R>>C;
dp[R][C], arr[R][C];
memset(dp,-1,sizeof(dp));
FOR(i,R){
FOR(j,C){
cin>>arr[i][j];
}
}
int sol = 0;
FOR(i,R){
FOR(j,C){
sol = max(sol, bfs(i,j));
}
}
printf("%s: %d\n", s.c_str(), ++sol);
}
return 0;
}