Problem C
Longest Run on a Snowboard
input: standard input
output: standard output
Time Limit: 5 Seconds
Memory Limit: MB
Michael likes snowboarding. That's not very surprising, since snowboarding is really great. The bad thing is, and the gain, the area must slide downwards. Another disadvantage is if you've reached the bottom of the hill you had to walk up again or wait for the Ski-lift .
Michael would like-to-know how long the longest run was in. That area was given by a grid of numbers, defining the heights at those points. Look at this example:
One can slide down from one point to a connected other one if and only if the height decreases. One point was connected to another if it's at left, at right, above or below it. In the sample map, a possible slide would is 24-17-16-1 (start at and end at 1). Of course if you would go 25-24-23-...-3-2-1, it would is a much longer run. In fact, it ' s the longest possible.
Input
The first line contains the number of test cases N. Each test case starts with a line containing the name (it's a single string), the number of rows R and the number of columns C. After this follow R lines with C numbers each, defining the heights. R and C won ' t is bigger than , N not bigger than and The Heights is always in t The He range is from 0 to.
For each test case, print a line containing the name of the area, a colon, a space and the length of the longest run one C An slide down in the that area.
Sample Output
Feldberg:7
Spiral:25
(Math Lovers ' Contest, problem Setter:stefan Pochmann)
Test instructions: Find the longest decreasing path length.
CODE:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string > #include <algorithm> #include <cstdlib> #include <set> #include <queue> #include <stack > #include <vector> #include <map> #define N 100010#define Mod 10000007#define Lson l,mid,idx<<1# Define Rson mid+1,r,idx<<1|1#define LC idx<<1#define RC Idx<<1|1const Double EPS = 1e-11;const double PI = ACOs ( -1.0); const double E = 2.718281828;typedef long long ll;const int INF = 1000010;using namespace Std;int mp[110] [110],dp[110][110];int N,m;char s[140];int xx[4]= { -1,0,1,0};int yy[4]= {0,1,0,-1};bool vis[110][110];int dfs (int x,int Y) {if (dp[x][y]!=1) return dp[x][y]; int Ans=1; for (int i=0; i<4; i++) {int nx=xx[i]+x; int ny=yy[i]+y; if (nx<0| | nx>=n| | ny<0| | ny>=m| | Mp[nx][ny]>=mp[x][y]) continue; Dp[x][y]=max (Dp[x][y],dfs (Nx,ny) +1); } return dp[x][y];} InchT main () {int t; while (~SCANF ("%d", &t)) {while (t--) {scanf ("%s", s); scanf ("%d%d", &n,&m); for (int. i=0; i<n; i++) for (int j=0; j<m; j + +) scanf ("%d", &mp[i][j]); int Ans=1; memset (vis,0,sizeof Vis); for (int i=0;i<=n+1;i++) fill (dp[i],dp[i]+m+1,1); for (int i=0, i<n; i++) for (int j=0; j<m; j + +) Ans=max (Ans,dfs (i,j)); printf ("%s:%d\n", S,ans); }} return 0;}
UVA 10285 the Tower of Babylon (memory search)