/*
DP: DAG上的最长路径
*/
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 105;
int m, n, t;
char loc[MAXN];
int grid[MAXN][MAXN];
int d[MAXN][MAXN];
int r, c;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int dp(int i, int j)
{
int &cur = d[i][j];
int &h = grid[i][j];
if(cur > 0) return cur;
cur = 1;
for(int k=0; k<4; k++) {
int tx = i + x[k];
int ty = j + y[k];
if(h > grid[tx][ty]) {
int val = dp(tx, ty);
if(val+1 > cur) cur = val + 1;
}
}
return cur;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
int T;
scanf("%d", &T);
while(T--) {
memset(grid, 0x7f, sizeof(grid));
scanf("%s%d%d", loc, &r, &c);
for(int i=1; i<=r; i++) {
for(int j=1; j<=c; j++) {
scanf("%d", &grid[i][j]);
}
}
memset(d, 0, sizeof(d));
int max_val = 1;
for(int i=1; i<=r; i++) {
for(int j=1; j<=c; j++) {
int val = dp(i, j);
if(val > max_val) max_val = val;
}
}
printf("%s: %d\n", loc, max_val);
}
return 0;
}
UVa 10285 - Longest Run on a Snowboard
最新推荐文章于 2018-12-13 08:38:26 发布