10285-longest Run on a snowboard
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=114&page=show_ problem&problem=1226
It's OK to write recursively.
Complete code:
/*0.025s*/#include <bits/stdc++.h> using namespace std; const int v[4][2] = {0,-1, 0, 1,-1, 0, 1, 0}; con
St int MAXN = 105;
Char NAME[MAXN];
int H[MAXN][MAXN], DP[MAXN][MAXN];
int f (int y, int x) {if (!dp[y][x]) {dp[y][x] = 1; for (int i = 0; i < 4; ++i) if (H[y][x] > h[y + v[i][0]][x + v[i][1]]) dp[y][x] = max (DP [Y]
[x], F (y + v[i][0], X + v[i][1]) + 1);
return dp[y][x];
int main () {int T, r, C, I, J, Maxrun;
scanf ("%d", &t);
while (t--) {scanf ("%s%d%d", Name, &r, &c);
memset (H, 0x3f, sizeof (h));
memset (DP, 0, sizeof (DP));
for (i = 1; I <= R. ++i) for (j = 1; j <= C; ++j) scanf ("%d", &h[i][j));
Maxrun = 0;
for (i = 1; I <= R. ++i) for (j = 1; j <= C; ++j) Maxrun = max (Maxrun, F (i, j));
printf ("%s:%d\n", name, Maxrun); } return 0; }
Author: csdn Blog Synapse7
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/